2011-01-22 06:53:24 +08:00
|
|
|
var helper = require(__dirname + "/test-helper");
|
|
|
|
var pg = helper.pg;
|
|
|
|
var conString = helper.connectionString();
|
|
|
|
|
|
|
|
test('parsing array results', function() {
|
|
|
|
pg.connect(conString, assert.calls(function(err, client) {
|
|
|
|
assert.isNull(err);
|
|
|
|
client.query("CREATE TEMP TABLE why(names text[], numbors integer[])");
|
|
|
|
client.query('INSERT INTO why(names, numbors) VALUES(\'{"aaron", "brian","a b c" }\', \'{1, 2, 3}\')').on('error', console.log);
|
|
|
|
test('numbers', function() {
|
|
|
|
// client.connection.on('message', console.log)
|
|
|
|
client.query('SELECT numbors FROM why', assert.success(function(result) {
|
2011-10-11 08:21:06 +08:00
|
|
|
assert.lengthIs(result.rows[0].numbors, 3);
|
2011-01-22 06:53:24 +08:00
|
|
|
assert.equal(result.rows[0].numbors[0], 1);
|
|
|
|
assert.equal(result.rows[0].numbors[1], 2);
|
|
|
|
assert.equal(result.rows[0].numbors[2], 3);
|
|
|
|
}))
|
|
|
|
})
|
|
|
|
|
|
|
|
test('parses string arrays', function() {
|
|
|
|
client.query('SELECT names FROM why', assert.success(function(result) {
|
|
|
|
var names = result.rows[0].names;
|
2011-10-11 08:21:06 +08:00
|
|
|
assert.lengthIs(names, 3);
|
2011-01-22 06:53:24 +08:00
|
|
|
assert.equal(names[0], 'aaron');
|
|
|
|
assert.equal(names[1], 'brian');
|
|
|
|
assert.equal(names[2], "a b c");
|
|
|
|
pg.end();
|
|
|
|
}))
|
|
|
|
})
|
|
|
|
}))
|
|
|
|
})
|
|
|
|
|
|
|
|
|