2013-05-20 22:03:54 +08:00
|
|
|
var domain = require('domain');
|
2011-03-01 12:59:54 +08:00
|
|
|
var helper = require(__dirname + "/../test-helper");
|
2011-08-12 09:59:56 +08:00
|
|
|
var Client = require(__dirname + "/../../lib/native");
|
2011-03-01 12:59:54 +08:00
|
|
|
|
|
|
|
test('fires callback with results', function() {
|
2011-11-22 11:42:43 +08:00
|
|
|
var client = new Client(helper.config);
|
2011-03-02 03:51:25 +08:00
|
|
|
client.connect();
|
|
|
|
client.query('SELECT 1 as num', assert.calls(function(err, result) {
|
|
|
|
assert.isNull(err);
|
|
|
|
assert.equal(result.rows[0].num, 1);
|
2015-02-23 04:30:22 +08:00
|
|
|
assert.strictEqual(result.rowCount, 1);
|
2011-03-02 03:51:25 +08:00
|
|
|
client.query('SELECT * FROM person WHERE name = $1', ['Brian'], assert.calls(function(err, result) {
|
|
|
|
assert.isNull(err);
|
|
|
|
assert.equal(result.rows[0].name, 'Brian');
|
|
|
|
client.end();
|
|
|
|
}))
|
2011-03-01 12:59:54 +08:00
|
|
|
}));
|
|
|
|
})
|
2013-05-20 22:03:54 +08:00
|
|
|
|
|
|
|
test('preserves domain', function() {
|
|
|
|
var dom = domain.create();
|
|
|
|
|
|
|
|
dom.run(function() {
|
|
|
|
var client = new Client(helper.config);
|
|
|
|
assert.ok(dom === require('domain').active, 'domain is active');
|
|
|
|
client.connect()
|
|
|
|
client.query('select 1', function() {
|
|
|
|
assert.ok(dom === require('domain').active, 'domain is still active');
|
|
|
|
client.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
})
|