Skip to content

Commit 1b9ccf9

Browse files
committed
reduced number of flush messages during prepared statement, 2x performance
1 parent aa53908 commit 1b9ccf9

File tree

3 files changed

+13
-20
lines changed

3 files changed

+13
-20
lines changed

lib/client.js

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,20 @@ p.prepare = function(connection) {
150150
return (val instanceof Date) ? JSON.stringify(val) : val;
151151
});
152152
}
153+
//http://developer.postgresql.org/pgdocs/postgres/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY
153154
connection.bind({
154155
portal: self.name,
155156
statement: self.name,
156157
values: self.values
157158
});
159+
connection.describe({
160+
type: 'P',
161+
name: self.name || ""
162+
});
163+
connection.execute({
164+
portal: self.name,
165+
rows: self.rows
166+
});
158167
connection.flush();
159168
};
160169

@@ -168,27 +177,10 @@ p.prepare = function(connection) {
168177
name: self.name,
169178
types: self.types
170179
});
171-
connection.flush();
172-
connection.once('parseComplete', onParseComplete);
180+
onParseComplete();
173181
}
174182

175183

176-
var onBindComplete = function() {
177-
connection.describe({
178-
type: 'P',
179-
name: self.name || ""
180-
});
181-
//http://developer.postgresql.org/pgdocs/postgres/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY
182-
//TODO get ourselves a rowDescription for result type coercion
183-
connection.execute({
184-
portal: self.name,
185-
rows: self.rows
186-
});
187-
connection.flush();
188-
};
189-
190-
connection.once('bindComplete', onBindComplete);
191-
192184
//TODO support EmptyQueryResponse, ErrorResponse, and PortalSuspended
193185
var onCommandComplete = function() {
194186
connection.sync();

test/integration/client/type-coercion-tests.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ var helper = require(__dirname + '/test-helper');
22

33
var client = helper.client();
44
client.on('drain', client.end.bind(client));
5+
56
var testForTypeCoercion = function(type){
67
client.query("create temp table test_type(col " + type.name + ")");
78

@@ -20,7 +21,7 @@ var testForTypeCoercion = function(type){
2021
});
2122

2223
assert.emits(query, 'row', function(row) {
23-
assert.strictEqual(row.fields[0], val);
24+
assert.strictEqual(row.fields[0], val, "expected " + type.name + " of " + val + " but got " + row.fields[0]);
2425
});
2526

2627
client.query({

test/test-helper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ assert.emits = function(item, eventName, callback) {
2323
test("Should have called " + eventName, function() {
2424
assert.ok(called, "Expected '" + eventName + "' to be called.")
2525
});
26-
},10000);
26+
},20000);
2727

2828
item.once(eventName, function() {
2929
called = true;

0 commit comments

Comments
 (0)