mirror of
https://github.com/brianc/node-postgres.git
synced 2026-01-18 15:55:05 +00:00
Break native result into its own file
This commit is contained in:
parent
5dff31387c
commit
21f6dbe006
@ -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
22
lib/native/result.js
Normal 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)
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user