将 node-postgres 连接到 PostgreSQL-dialect 数据库
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
本页面介绍了如何将 PostgreSQL node-postgres 驱动程序连接到 PostgreSQL-dialect 数据库
。node-postgres 是适用于 PostgreSQL 的 Node.js 驱动程序。
确保 PGAdapter 与
使用 PostgreSQL node-postgres 驱动程序建立连接。
如需了解详情,请参阅启动 PGAdapter。
指定 localhost
和 5432
作为数据库服务器主机和
node-postgres
连接属性。
- (可选)如果 PGAdapter 为
配置为在非默认 PostgreSQL 端口上进行监听
端口 (5432)。
- (可选)如果 PGAdapter 正在运行,请指定其他主机名
与本地机器位于不同主机上
const { Client } = require('pg');
const client = new Client({
host: 'localhost',
port: 5432,
database: 'my-database',
});
await client.connect();
const res = await client.query("select 'Hello world!' as hello");
console.log(res.rows[0].hello);
await client.end();
后续步骤
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-07-19。
[{
"type": "thumb-down",
"id": "hardToUnderstand",
"label":"Hard to understand"
},{
"type": "thumb-down",
"id": "incorrectInformationOrSampleCode",
"label":"Incorrect information or sample code"
},{
"type": "thumb-down",
"id": "missingTheInformationSamplesINeed",
"label":"Missing the information/samples I need"
},{
"type": "thumb-down",
"id": "translationIssue",
"label":"翻译问题"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"其他"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"易于理解"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"解决了我的问题"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"其他"
}]