forked from brianc/node-postgres
-
Notifications
You must be signed in to change notification settings - Fork 0
brianc edited this page Dec 18, 2010
·
35 revisions
pg is an small object which provides transparent Client life-cycle management and client pooling.
You're absolutely free to bypass the pg class completely in favor of your own client pool implementation; however, it is very, very not recommended to create an individual, new Client instance for each request to a web server. It will work fine in development but once your web server receives more simultaneous requests than your PostgreSQL server can support, your new Client instances will all emit the error event when they attempt to connect and you will be in...how you say...a world of hurt.
require('pg');
var connectionString = "pg://brian:1234@localhost/postgres"
pg.connect(connectionString, function(err, client) {
client.query('SELECT name FROM users WHERE email = $1', ['brian@example.com'], function(err, result) {
assert.equal('brianc', result.rows[0].name);
});
});