2010-10-25 14:40:24 +08:00
|
|
|
var helper = require(__dirname+"/test-helper");
|
|
|
|
//before running this test make sure you run the script create-test-tables
|
2010-10-26 14:47:05 +08:00
|
|
|
test("simple query interface", function() {
|
|
|
|
|
2010-10-25 14:40:24 +08:00
|
|
|
var client = helper.client();
|
2010-10-26 13:31:58 +08:00
|
|
|
|
2010-10-26 14:47:05 +08:00
|
|
|
var query = client.query("select name from person");
|
|
|
|
|
2010-10-30 09:10:49 +08:00
|
|
|
client.on('drain', client.end.bind(client));
|
|
|
|
|
2010-10-26 14:47:05 +08:00
|
|
|
var rows = [];
|
2010-10-25 14:40:24 +08:00
|
|
|
query.on('row', function(row) {
|
2010-10-26 14:47:05 +08:00
|
|
|
rows.push(row.fields[0])
|
2010-10-25 14:40:24 +08:00
|
|
|
});
|
2010-10-26 14:47:05 +08:00
|
|
|
|
2010-10-25 14:40:24 +08:00
|
|
|
assert.raises(query, 'end', function() {
|
2010-10-26 14:47:05 +08:00
|
|
|
test("returned right number of rows", function() {
|
|
|
|
assert.length(rows, 26);
|
|
|
|
});
|
|
|
|
test("row ordering", function(){
|
|
|
|
assert.equal(rows[0], "Aaron");
|
|
|
|
assert.equal(rows[25], "Zanzabar");
|
|
|
|
});
|
2010-10-25 14:40:24 +08:00
|
|
|
});
|
2010-10-30 09:10:49 +08:00
|
|
|
});
|
2010-10-25 14:40:24 +08:00
|
|
|
|
2010-10-30 09:10:49 +08:00
|
|
|
test("multiple simple queries", function() {
|
|
|
|
var client = helper.client();
|
|
|
|
client.query("create temp table bang(id serial, name varchar(5));insert into bang(name) VALUES('boom');")
|
|
|
|
client.query("insert into bang(name) VALUES ('yes');");
|
|
|
|
var query = client.query("select name from bang");
|
|
|
|
assert.raises(query, 'row', function(row) {
|
|
|
|
assert.equal(row.fields[0], 'boom');
|
|
|
|
assert.raises(query, 'row', function(row) {
|
|
|
|
assert.equal(row.fields[0],'yes');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
client.on('drain', client.end.bind(client));
|
2010-10-25 14:40:24 +08:00
|
|
|
});
|
2010-10-26 14:47:05 +08:00
|
|
|
|