将 node-postgres 连接到 PostgreSQL 方言数据库
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
本页面介绍如何将 PostgreSQL node-postgres 驱动程序连接到 Spanner 中的 PostgreSQL 方言数据库。node-postgres 是适用于 PostgreSQL 的 Node.js 驱动程序。
确保 PGAdapter 与使用 PostgreSQL node-postgres 驱动程序连接的应用在同一机器上运行。
如需了解详情,请参阅启动 PGAdapter。
在 node-postgres
连接属性中,将 localhost
和 5432
指定为数据库服务器主机和端口。
- (可选)如果 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-02-01。
[{
"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":"其他"
}]