2014-10-18 12:27:28 +08:00
|
|
|
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];
|
2015-02-22 00:32:39 +08:00
|
|
|
this.rowCount = parseInt(pq.cmdTuples(), 10);
|
2014-10-18 12:27:28 +08:00
|
|
|
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)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
2016-02-12 10:38:38 +08:00
|
|
|
|
|
|
|
NativeResult.prototype.addRow = function(row) {
|
|
|
|
// This is empty to ensure pg code doesn't break when switching to pg-native
|
|
|
|
// pg-native loads all rows into the final result object by default.
|
|
|
|
// This is because libpg loads all rows into memory before passing the result
|
|
|
|
// to pg-native.
|
|
|
|
};
|