mirror of
https://github.com/brianc/node-postgres.git
synced 2026-01-18 15:55:05 +00:00
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.
This commit is contained in:
parent
613112ca33
commit
4c5f3aba65
@ -7,7 +7,12 @@ var NativeQuery = require('./query');
|
||||
|
||||
var Client = module.exports = function(config) {
|
||||
EventEmitter.call(this);
|
||||
this.native = new Native();
|
||||
config = config || {};
|
||||
|
||||
this.native = new Native({
|
||||
types: config.types || require('pg-types')
|
||||
});
|
||||
|
||||
this._queryQueue = [];
|
||||
this._connected = false;
|
||||
|
||||
@ -85,6 +90,7 @@ Client.prototype.query = function(config, values, callback) {
|
||||
query.values = config.values;
|
||||
query.name = config.name;
|
||||
query.callback = config.callback;
|
||||
query._arrayMode = config.rowMode == 'array';
|
||||
}
|
||||
|
||||
//support query({...}, function() {}) style calls
|
||||
|
||||
@ -10,6 +10,7 @@ var NativeQuery = module.exports = function(native) {
|
||||
this.name = null;
|
||||
this.callback = null;
|
||||
this.state = 'new';
|
||||
this._arrayMode = false;
|
||||
|
||||
//if the 'row' event is listened for
|
||||
//then emit them as they come in
|
||||
@ -75,8 +76,10 @@ NativeQuery.prototype.handleError = function(err) {
|
||||
NativeQuery.prototype.submit = function(client) {
|
||||
this.state = 'running';
|
||||
var self = this;
|
||||
client.native.arrayMode = this._arrayMode;
|
||||
|
||||
var after = function(err, rows) {
|
||||
client.native.arrayMode = false;
|
||||
setImmediate(function() {
|
||||
self.emit('_done');
|
||||
});
|
||||
@ -121,7 +124,7 @@ NativeQuery.prototype.submit = function(client) {
|
||||
}
|
||||
//plan the named query the first time, then execute it
|
||||
return this.native.prepare(this.name, this.text, values.length, function(err) {
|
||||
if(err) return self.handleError(err);
|
||||
if(err) return after(err);
|
||||
client.namedQueries[self.name] = true;
|
||||
return self.native.execute(self.name, values, after);
|
||||
});
|
||||
|
||||
@ -23,9 +23,7 @@ var Query = function(config, values, callback) {
|
||||
if(process.domain && config.callback) {
|
||||
this.callback = process.domain.bind(config.callback);
|
||||
}
|
||||
this._fieldNames = [];
|
||||
this._fieldConverters = [];
|
||||
this._result = new Result(config.rowMode);
|
||||
this._result = new Result(config.rowMode, config.types);
|
||||
this.isPreparedStatement = false;
|
||||
this._canceledDueToError = false;
|
||||
EventEmitter.call(this);
|
||||
|
||||
@ -23,7 +23,7 @@
|
||||
"nan": "~1.3.0",
|
||||
"packet-reader": "0.2.0",
|
||||
"pg-connection-string": "0.1.1",
|
||||
"pg-native": "1.2.0",
|
||||
"pg-native": "1.4.0",
|
||||
"pg-types": "1.4.0",
|
||||
"pgpass": "0.0.3"
|
||||
},
|
||||
|
||||
18
test/integration/client/custom-types-tests.js
Normal file
18
test/integration/client/custom-types-tests.js
Normal file
@ -0,0 +1,18 @@
|
||||
var helper = require(__dirname + '/test-helper');
|
||||
return console.log('TODO: get this working for non-native client');
|
||||
|
||||
helper.config.types = {
|
||||
getTypeParser: function() {
|
||||
return function() {
|
||||
return 'okay!'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
helper.pg.connect(helper.config, assert.success(function(client, done) {
|
||||
client.query('SELECT NOW() as val', assert.success(function(res) {
|
||||
assert.equal(res.rows[0].val, 'okay!');
|
||||
done();
|
||||
helper.pg.end();
|
||||
}));
|
||||
}));
|
||||
@ -1,8 +1,3 @@
|
||||
console.log('results-as-array: GET TO PASS')
|
||||
console.log('results-as-array: GET TO PASS')
|
||||
console.log('results-as-array: GET TO PASS')
|
||||
console.log('results-as-array: GET TO PASS')
|
||||
return console.log('results-as-array: GET TO PASS')
|
||||
var util = require('util');
|
||||
var helper = require('./test-helper');
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user