node-postgres/test/integration/connection/query-tests.js

31 lines
866 B
JavaScript
Raw Normal View History

2010-10-24 02:56:38 +08:00
var helper = require(__dirname+"/test-helper");
var assert = require('assert');
2010-10-24 05:21:11 +08:00
2010-10-24 02:56:38 +08:00
var rows = [];
//testing the low level 1-1 mapping api of client to postgres messages
//it's cumbersome to use the api this way
2010-10-24 05:21:11 +08:00
helper.connect(function(con) {
con.query('select * from ids');
con.on('dataRow', function(msg) {
2010-10-24 09:26:24 +08:00
console.log("row: " + sys.inspect(msg.fields));
2010-10-24 05:21:11 +08:00
rows.push(msg.fields);
});
con.once('readyForQuery', function() {
con.end();
});
2010-10-03 14:14:19 +08:00
});
2010-10-24 02:56:38 +08:00
process.on('exit', function() {
2010-10-24 05:21:11 +08:00
assert.equal(rows.length, 2);
2010-10-24 02:56:38 +08:00
assert.equal(rows[0].length, 1);
2010-10-24 09:26:24 +08:00
assert.strictEqual(rows[0] [0], '1');
assert.strictEqual(rows[1] [0], '2');
});
2010-10-03 14:14:19 +08:00
2010-10-03 13:45:10 +08:00
// client.query('create temporary table bang (id integer)');
// client.query('insert into bang(id) VALUES(1)');
// client.query('select * from bang',function(err, results, fields) {
// assert.equal(err, null);
// });