/usr/lib/nodejs/pg/native/query.js is in node-pg 0.13.3-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | var EventEmitter = require('events').EventEmitter;
var util = require('util');
var types = require(__dirname + '/../types/');
var utils = require(__dirname + '/../utils');
var Result = require(__dirname + '/../result');
//event emitter proxy
var NativeQuery = function(config, values, callback) {
// use of "new" optional
if (!(this instanceof NativeQuery)) {
return new NativeQuery(config, values, callback);
}
EventEmitter.call(this);
var c = utils.normalizeQueryConfig(config, values, callback);
this.name = c.name;
this.text = c.text;
this.values = c.values;
this.callback = c.callback;
this._result = new Result();
//normalize values
if(this.values) {
for(var i = 0, len = this.values.length; i < len; i++) {
this.values[i] = utils.prepareValue(this.values[i]);
}
}
this._canceledDueToError = false;
};
util.inherits(NativeQuery, EventEmitter);
//maps from native rowdata into api compatible row object
var mapRowData = function(row) {
var result = {};
for(var i = 0, len = row.length; i < len; i++) {
var item = row[i];
result[item.name] = item.value === null ? null :
types.getTypeParser(item.type, 'text')(item.value);
}
return result;
};
NativeQuery.prototype.handleRow = function(rowData) {
var row = mapRowData(rowData);
if(this.callback) {
this._result.addRow(row);
}
this.emit('row', row, this._result);
};
NativeQuery.prototype.handleError = function(error) {
if (this._canceledDueToError) {
error = this._canceledDueToError;
this._canceledDueToError = false;
}
if(this.callback) {
this.callback(error);
this.callback = null;
} else {
this.emit('error', error);
}
};
NativeQuery.prototype.handleReadyForQuery = function(meta) {
if (this._canceledDueToError) {
return this.handleError(this._canceledDueToError);
}
if(meta) {
this._result.addCommandComplete(meta);
}
if(this.callback) {
this.callback(null, this._result);
}
this.emit('end', this._result);
};
NativeQuery.prototype.streamData = function (connection) {
if(this.stream) {
this.stream.startStreamingToConnection(connection);
}
else {
connection.sendCopyFail('No source stream defined');
}
};
NativeQuery.prototype.handleCopyFromChunk = function (chunk) {
if(this.stream) {
this.stream.handleChunk(chunk);
}
//if there are no stream (for example when copy to query was sent by
//query method instead of copyTo) error will be handled
//on copyOutResponse event, so silently ignore this error here
};
module.exports = NativeQuery;
|