mirror of
https://github.com/brianc/node-postgres.git
synced 2026-01-25 16:03:13 +00:00
Clients are not reusable. This changes the client to raise errors whenever you try to reconnect a client that's already been used. They're cheap to create: just instantiate a new one (or use the pool) 😉. Closes #1352
33 lines
1.1 KiB
JavaScript
33 lines
1.1 KiB
JavaScript
"use strict";
|
|
var helper = require("./test-helper");
|
|
var pg = helper.pg;
|
|
|
|
const pool = new pg.Pool()
|
|
new helper.Suite().test('should return insert metadata', function() {
|
|
pool.connect(assert.calls(function(err, client, done) {
|
|
assert(!err);
|
|
|
|
helper.versionGTE(client, '9.0.0', assert.success(function(hasRowCount) {
|
|
client.query("CREATE TEMP TABLE zugzug(name varchar(10))", assert.calls(function(err, result) {
|
|
assert(!err);
|
|
assert.equal(result.oid, null);
|
|
assert.equal(result.command, 'CREATE');
|
|
|
|
var q = client.query("INSERT INTO zugzug(name) VALUES('more work?')", assert.calls(function(err, result) {
|
|
assert(!err);
|
|
assert.equal(result.command, "INSERT");
|
|
assert.equal(result.rowCount, 1);
|
|
|
|
client.query('SELECT * FROM zugzug', assert.calls(function(err, result) {
|
|
assert(!err);
|
|
if(hasRowCount) assert.equal(result.rowCount, 1);
|
|
assert.equal(result.command, 'SELECT');
|
|
done();
|
|
process.nextTick(pool.end.bind(pool));
|
|
}));
|
|
}));
|
|
}));
|
|
}));
|
|
}));
|
|
});
|