2010-11-15 13:04:41 +08:00
|
|
|
var helper = require(__dirname + '/../test-helper');
|
|
|
|
var pg = require(__dirname + '/../../../lib');
|
|
|
|
|
2010-11-15 14:10:21 +08:00
|
|
|
var connected = false
|
2010-11-15 14:42:38 +08:00
|
|
|
var simpleCalled = false
|
|
|
|
var preparedCalled = false
|
|
|
|
|
2010-11-15 14:10:21 +08:00
|
|
|
pg.connect(helper.args, function(err, client) {
|
|
|
|
connected = true
|
|
|
|
test('error is null', function() {
|
|
|
|
assert.equal(err, null)
|
|
|
|
})
|
|
|
|
|
2010-11-15 14:42:38 +08:00
|
|
|
test('simple query execution', function() {
|
2010-11-15 14:10:21 +08:00
|
|
|
client.query('CREATE TEMP TABLE band(name varchar(100))')
|
|
|
|
client.query("INSERT INTO band (name) VALUES ('dead black hearts')")
|
|
|
|
client.query("SELECT * FROM band WHERE name = 'dead black hearts'", function(err, result) {
|
2010-11-15 14:42:38 +08:00
|
|
|
simpleCalled = true
|
2010-11-15 14:10:21 +08:00
|
|
|
assert.equal(result.rows.pop().name, 'dead black hearts')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2010-11-15 14:42:38 +08:00
|
|
|
test('prepared statement execution', function() {
|
|
|
|
client.query('SELECT * FROM band WHERE name = $1', ['dead black hearts'], function(err, result) {
|
|
|
|
preparedCalled = true
|
|
|
|
assert.equal(result.rows.pop().name, 'dead black hearts')
|
|
|
|
})
|
|
|
|
})
|
2010-11-15 14:10:21 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
process.on('exit', function() {
|
|
|
|
assert.ok(connected, 'never connected')
|
2010-11-15 14:42:38 +08:00
|
|
|
assert.ok(simpleCalled, 'query result callback was never called')
|
|
|
|
assert.ok(preparedCalled, 'prepared callback was never called')
|
2010-11-15 14:10:21 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
test('raises error if cannot connect', function() {
|
|
|
|
pg.connect({database:'asdlfkajsdf there is no way this is a real database, right?!'}, function(err, client) {
|
|
|
|
assert.ok(err, 'error was null')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2010-11-15 13:04:41 +08:00
|
|
|
|