diff --git a/lib/native/query.js b/lib/native/query.js index 4ca9cc24..29b77ba9 100644 --- a/lib/native/query.js +++ b/lib/native/query.js @@ -1,6 +1,7 @@ var EventEmitter = require('events').EventEmitter; var util = require('util'); var utils = require('../utils'); +var NativeResult = require('./result'); var NativeQuery = module.exports = function(native) { EventEmitter.call(this); @@ -25,37 +26,6 @@ var NativeQuery = module.exports = function(native) { util.inherits(NativeQuery, EventEmitter); -//given an array of values, turn all `undefined` into `null` -var clean = function(values) { - for(var i = 0; i < values.length; i++) { - if(typeof values[i] == 'undefined') { - values[i] = null; - } - } -}; - -var NativeResult = function(pq) { - this.command = null; - this.rowCount = 0; - this.rows = null; - this.fields = null; -}; - -NativeResult.prototype.addCommandComplete = function(pq) { - this.command = pq.cmdStatus().split(' ')[0]; - this.rowCount = pq.cmdTuples(); - var nfields = pq.nfields(); - if(nfields < 1) return; - - this.fields = []; - for(var i = 0; i < nfields; i++) { - this.fields.push({ - name: pq.fname(i), - dataTypeID: pq.ftype(i) - }); - } -}; - NativeQuery.prototype.handleError = function(err) { var self = this; //copy pq error fields into the error object diff --git a/lib/native/result.js b/lib/native/result.js new file mode 100644 index 00000000..5e202f1f --- /dev/null +++ b/lib/native/result.js @@ -0,0 +1,22 @@ +var NativeResult = module.exports = function(pq) { + this.command = null; + this.rowCount = 0; + this.rows = null; + this.fields = null; +}; + +NativeResult.prototype.addCommandComplete = function(pq) { + this.command = pq.cmdStatus().split(' ')[0]; + this.rowCount = pq.cmdTuples(); + var nfields = pq.nfields(); + if(nfields < 1) return; + + this.fields = []; + for(var i = 0; i < nfields; i++) { + this.fields.push({ + name: pq.fname(i), + dataTypeID: pq.ftype(i) + }); + } +}; +