Skip to content

Commit 4c5f3ab

Browse files
committed
Add support for native rowMode: array
This completes the port from the old native bindings to the new node-pg-native bindings! Time to build in support for older versions of postgres & start the pull request process.
1 parent 613112c commit 4c5f3ab

File tree

6 files changed

+31
-11
lines changed

6 files changed

+31
-11
lines changed

lib/native/index.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ var NativeQuery = require('./query');
77

88
var Client = module.exports = function(config) {
99
EventEmitter.call(this);
10-
this.native = new Native();
10+
config = config || {};
11+
12+
this.native = new Native({
13+
types: config.types || require('pg-types')
14+
});
15+
1116
this._queryQueue = [];
1217
this._connected = false;
1318

@@ -85,6 +90,7 @@ Client.prototype.query = function(config, values, callback) {
8590
query.values = config.values;
8691
query.name = config.name;
8792
query.callback = config.callback;
93+
query._arrayMode = config.rowMode == 'array';
8894
}
8995

9096
//support query({...}, function() {}) style calls

lib/native/query.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ var NativeQuery = module.exports = function(native) {
1010
this.name = null;
1111
this.callback = null;
1212
this.state = 'new';
13+
this._arrayMode = false;
1314

1415
//if the 'row' event is listened for
1516
//then emit them as they come in
@@ -75,8 +76,10 @@ NativeQuery.prototype.handleError = function(err) {
7576
NativeQuery.prototype.submit = function(client) {
7677
this.state = 'running';
7778
var self = this;
79+
client.native.arrayMode = this._arrayMode;
7880

7981
var after = function(err, rows) {
82+
client.native.arrayMode = false;
8083
setImmediate(function() {
8184
self.emit('_done');
8285
});
@@ -121,7 +124,7 @@ NativeQuery.prototype.submit = function(client) {
121124
}
122125
//plan the named query the first time, then execute it
123126
return this.native.prepare(this.name, this.text, values.length, function(err) {
124-
if(err) return self.handleError(err);
127+
if(err) return after(err);
125128
client.namedQueries[self.name] = true;
126129
return self.native.execute(self.name, values, after);
127130
});

lib/query.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ var Query = function(config, values, callback) {
2323
if(process.domain && config.callback) {
2424
this.callback = process.domain.bind(config.callback);
2525
}
26-
this._fieldNames = [];
27-
this._fieldConverters = [];
28-
this._result = new Result(config.rowMode);
26+
this._result = new Result(config.rowMode, config.types);
2927
this.isPreparedStatement = false;
3028
this._canceledDueToError = false;
3129
EventEmitter.call(this);

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"nan": "~1.3.0",
2424
"packet-reader": "0.2.0",
2525
"pg-connection-string": "0.1.1",
26-
"pg-native": "1.2.0",
26+
"pg-native": "1.4.0",
2727
"pg-types": "1.4.0",
2828
"pgpass": "0.0.3"
2929
},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
var helper = require(__dirname + '/test-helper');
2+
return console.log('TODO: get this working for non-native client');
3+
4+
helper.config.types = {
5+
getTypeParser: function() {
6+
return function() {
7+
return 'okay!'
8+
}
9+
}
10+
};
11+
12+
helper.pg.connect(helper.config, assert.success(function(client, done) {
13+
client.query('SELECT NOW() as val', assert.success(function(res) {
14+
assert.equal(res.rows[0].val, 'okay!');
15+
done();
16+
helper.pg.end();
17+
}));
18+
}));

test/integration/client/results-as-array-tests.js

-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
console.log('results-as-array: GET TO PASS')
2-
console.log('results-as-array: GET TO PASS')
3-
console.log('results-as-array: GET TO PASS')
4-
console.log('results-as-array: GET TO PASS')
5-
return console.log('results-as-array: GET TO PASS')
61
var util = require('util');
72
var helper = require('./test-helper');
83

0 commit comments

Comments
 (0)