我无法在渲染中查询我的 Postgres 数据库。我在网上研究了这个问题,发现这是一个常见问题,但我找到的解决方案都不起作用。
这是我的服务器端代码(我使用 NodeJS、Express、Typescript 和 Postgres)
import postgres, { RowList, Row } from 'postgres'
import appconfig from '../app.config'
type Query = (sql: string) => Promise<RowList<Row[]>>
const query: Query = async (sql) => {
try {
const q = postgres({
host: appconfig.database.host,
port: appconfig.database.port,
database: appconfig.database.schema,
username: appconfig.database.username,
password: appconfig.database.password,
})
const res = await q`${sql}`
return res
} catch (err) {
throw err
}
}
export default query
Run Code Online (Sandbox Code Playgroud)
我每次都会收到以下错误,并且没有成功尝试。值得注意的是,我在同一台 PC 上使用相同的凭据从 PGAdmin 连接没有任何问题
Error: read ECONNRESET
at TCP.onStreamRead (node:internal/stream_base_commons:217:20) …Run Code Online (Sandbox Code Playgroud)