Break native result into its own file

This commit is contained in:
Brian M. Carlson 2014-10-18 00:27:28 -04:00
parent 5dff31387c
commit 21f6dbe006
2 changed files with 23 additions and 31 deletions

View File

@ -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

22
lib/native/result.js Normal file
View File

@ -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)
});
}
};