Skip to content

Commit 21f6dbe

Browse files
committed
Break native result into its own file
1 parent 5dff313 commit 21f6dbe

File tree

2 files changed

+23
-31
lines changed

2 files changed

+23
-31
lines changed

lib/native/query.js

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var EventEmitter = require('events').EventEmitter;
22
var util = require('util');
33
var utils = require('../utils');
4+
var NativeResult = require('./result');
45

56
var NativeQuery = module.exports = function(native) {
67
EventEmitter.call(this);
@@ -25,37 +26,6 @@ var NativeQuery = module.exports = function(native) {
2526

2627
util.inherits(NativeQuery, EventEmitter);
2728

28-
//given an array of values, turn all `undefined` into `null`
29-
var clean = function(values) {
30-
for(var i = 0; i < values.length; i++) {
31-
if(typeof values[i] == 'undefined') {
32-
values[i] = null;
33-
}
34-
}
35-
};
36-
37-
var NativeResult = function(pq) {
38-
this.command = null;
39-
this.rowCount = 0;
40-
this.rows = null;
41-
this.fields = null;
42-
};
43-
44-
NativeResult.prototype.addCommandComplete = function(pq) {
45-
this.command = pq.cmdStatus().split(' ')[0];
46-
this.rowCount = pq.cmdTuples();
47-
var nfields = pq.nfields();
48-
if(nfields < 1) return;
49-
50-
this.fields = [];
51-
for(var i = 0; i < nfields; i++) {
52-
this.fields.push({
53-
name: pq.fname(i),
54-
dataTypeID: pq.ftype(i)
55-
});
56-
}
57-
};
58-
5929
NativeQuery.prototype.handleError = function(err) {
6030
var self = this;
6131
//copy pq error fields into the error object

lib/native/result.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
var NativeResult = module.exports = function(pq) {
2+
this.command = null;
3+
this.rowCount = 0;
4+
this.rows = null;
5+
this.fields = null;
6+
};
7+
8+
NativeResult.prototype.addCommandComplete = function(pq) {
9+
this.command = pq.cmdStatus().split(' ')[0];
10+
this.rowCount = pq.cmdTuples();
11+
var nfields = pq.nfields();
12+
if(nfields < 1) return;
13+
14+
this.fields = [];
15+
for(var i = 0; i < nfields; i++) {
16+
this.fields.push({
17+
name: pq.fname(i),
18+
dataTypeID: pq.ftype(i)
19+
});
20+
}
21+
};
22+

0 commit comments

Comments
 (0)