node-postgres/test/integration/connection/bound-command-tests.js

61 lines
1.3 KiB
JavaScript
Raw Normal View History

2010-10-24 05:21:11 +08:00
var helper = require(__dirname + '/test-helper');
//http://developer.postgresql.org/pgdocs/postgres/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY
2010-10-24 05:21:11 +08:00
2010-10-24 11:07:00 +08:00
test('flushing once', function() {
helper.connect(function(con) {
con.parse({
text: 'select * from ids'
});
2010-10-26 10:43:55 +08:00
2010-10-24 05:21:11 +08:00
con.bind();
2010-10-24 11:07:00 +08:00
con.execute();
2010-10-24 05:21:11 +08:00
con.flush();
2010-10-26 10:43:55 +08:00
assert.emits(con, 'parseComplete');
assert.emits(con, 'bindComplete');
assert.emits(con, 'dataRow');
assert.emits(con, 'commandComplete', function(){
2010-10-24 11:07:00 +08:00
con.sync();
});
assert.emits(con, 'readyForQuery', function(){
2010-10-24 11:07:00 +08:00
con.end();
});
2010-10-26 10:43:55 +08:00
2010-10-24 05:21:11 +08:00
});
2010-10-24 11:07:00 +08:00
});
test("sending many flushes", function() {
helper.connect(function(con) {
assert.emits(con, 'parseComplete', function(){
2010-10-24 11:07:00 +08:00
con.bind();
con.flush();
});
2010-10-24 05:21:11 +08:00
assert.emits(con, 'bindComplete', function(){
2010-10-24 11:07:00 +08:00
con.execute();
con.flush();
});
2010-10-24 09:26:24 +08:00
assert.emits(con, 'dataRow', function(msg){
2010-10-26 10:43:55 +08:00
assert.equal(msg.fields[0], 1);
assert.emits(con, 'dataRow', function(msg){
2010-10-26 10:43:55 +08:00
assert.equal(msg.fields[0], 2);
assert.emits(con, 'commandComplete', function(){
2010-10-26 10:43:55 +08:00
con.sync();
});
assert.emits(con, 'readyForQuery', function(){
2010-10-26 10:43:55 +08:00
con.end();
});
});
2010-10-24 11:07:00 +08:00
});
2010-10-24 05:21:11 +08:00
2010-10-26 10:43:55 +08:00
con.parse({
text: "select * from ids order by id"
2010-10-24 11:07:00 +08:00
});
2010-10-24 05:21:11 +08:00
2010-10-26 10:43:55 +08:00
con.flush();
2010-10-24 11:07:00 +08:00
});
});