337d49dddb
Closes #209 Native implementation requires significant refactor and so I wont work on this if/until there is an issue for it
47 lines
1.1 KiB
JavaScript
47 lines
1.1 KiB
JavaScript
//result object returned from query
|
|
//in the 'end' event and also
|
|
//passed as second argument to provided callback
|
|
var Result = function() {
|
|
this.command = null;
|
|
this.rowCount = null;
|
|
this.oid = null;
|
|
this.rows = [];
|
|
this.fields = [];
|
|
};
|
|
|
|
var matchRegexp = /([A-Za-z]+) ?(\d+ )?(\d+)?/;
|
|
|
|
//adds a command complete message
|
|
Result.prototype.addCommandComplete = function(msg) {
|
|
var match;
|
|
if(msg.text) {
|
|
//pure javascript
|
|
match = matchRegexp.exec(msg.text);
|
|
} else {
|
|
//native bindings
|
|
match = matchRegexp.exec(msg.command);
|
|
}
|
|
if(match) {
|
|
this.command = match[1];
|
|
//match 3 will only be existing on insert commands
|
|
if(match[3]) {
|
|
//msg.value is from native bindings
|
|
this.rowCount = parseInt(match[3] || msg.value, 10);
|
|
this.oid = parseInt(match[2], 10);
|
|
} else {
|
|
this.rowCount = parseInt(match[2], 10);
|
|
}
|
|
}
|
|
};
|
|
|
|
Result.prototype.addRow = function(row) {
|
|
this.rows.push(row);
|
|
};
|
|
|
|
//Add a field definition to the result
|
|
Result.prototype.addField = function(field) {
|
|
this.fields.push(field);
|
|
};
|
|
|
|
module.exports = Result;
|