在Node中使用Postgres连接的正确方法是什么?

我想知道是否有人可以帮助我了解通过以下方式维护多个连接到多个postgres服务器的正确方法: https : //github.com/brianc/node-postgres

显然,当运行一个节点服务器很长一段时间,我们要确保我们保持一切清洁,没有泄漏,所以我想知道什么是适当的模式。

请记住,我的节点服务器将需要连接到7-8 Postgres服务器..

https://github.com/brianc/node-postgres支持池的想法,我想知道,我只是连接到初始节点服务器设置上的所有服务器,并保持开放连接,每个function可以要求一个池,当它需要与服务器交谈?

所以换句话说,我应该cal pg.connect EVERYTIME我做一个服务器查询(减去var pg和var连接string可能是全球性的)。 我不能只有一个连接,准备好了吗?

var pg = require('pg'); var connectionString = "pg://brian:1234@localhost/postgres" pg.connect(connectionString, function(err, client, done) { client.query('SELECT name FROM users WHERE email = $1', ['brian@example.com'], function(err, result) { assert.equal('brianc', result.rows[0].name); done(); }); }); 

代码片断非常感谢,

谢谢,

肖恩。