reduced number of flush messages during prepared statement, 2x performance

This commit is contained in:
brianc 2010-11-02 18:37:20 -05:00
parent aa53908e88
commit 1b9ccf97e9
3 changed files with 13 additions and 20 deletions

View File

@ -150,11 +150,20 @@ p.prepare = function(connection) {
return (val instanceof Date) ? JSON.stringify(val) : val;
});
}
//http://developer.postgresql.org/pgdocs/postgres/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY
connection.bind({
portal: self.name,
statement: self.name,
values: self.values
});
connection.describe({
type: 'P',
name: self.name || ""
});
connection.execute({
portal: self.name,
rows: self.rows
});
connection.flush();
};
@ -168,27 +177,10 @@ p.prepare = function(connection) {
name: self.name,
types: self.types
});
connection.flush();
connection.once('parseComplete', onParseComplete);
onParseComplete();
}
var onBindComplete = function() {
connection.describe({
type: 'P',
name: self.name || ""
});
//http://developer.postgresql.org/pgdocs/postgres/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY
//TODO get ourselves a rowDescription for result type coercion
connection.execute({
portal: self.name,
rows: self.rows
});
connection.flush();
};
connection.once('bindComplete', onBindComplete);
//TODO support EmptyQueryResponse, ErrorResponse, and PortalSuspended
var onCommandComplete = function() {
connection.sync();

View File

@ -2,6 +2,7 @@ var helper = require(__dirname + '/test-helper');
var client = helper.client();
client.on('drain', client.end.bind(client));
var testForTypeCoercion = function(type){
client.query("create temp table test_type(col " + type.name + ")");
@ -20,7 +21,7 @@ var testForTypeCoercion = function(type){
});
assert.emits(query, 'row', function(row) {
assert.strictEqual(row.fields[0], val);
assert.strictEqual(row.fields[0], val, "expected " + type.name + " of " + val + " but got " + row.fields[0]);
});
client.query({

View File

@ -23,7 +23,7 @@ assert.emits = function(item, eventName, callback) {
test("Should have called " + eventName, function() {
assert.ok(called, "Expected '" + eventName + "' to be called.")
});
},10000);
},20000);
item.once(eventName, function() {
called = true;