我刚接触typescript和nodejs。我想将运行在node上的服务器连接到容器化环境中的postgresdb。在没有typescirpt (只有java script )的情况下,有一些这样的例子。任何例子或链接都会很有帮助。
谢谢
编辑:此JS示例
const { Client } = require('pg')
const client = new Client()
await client.connect()
const res = await client.query('SELECT $1::text as message', ['Hello world!'])
console.log(res.rows[0].message) // Hello world!
await client.end()这是取自https://node-postgres.com/的例子,我们能把它转换成typescript吗,使用typescirpt是设计上的决定,所以我不能使用javascript,我想在放弃之前尝试一些东西和实验。
发布于 2018-12-19 21:30:46
我最终使用了typeorm,它可以与TS一起使用。https://github.com/typeorm/typeorm
Github Repo中提供了安装和示例。https://github.com/typeorm/typeorm#Installation
这可能不适用于所有人,但似乎最适合我,而且这个库看起来很稳定。
https://stackoverflow.com/questions/53760130
复制相似问题