node-postgres/lib/result.js

43 lines
960 B
JavaScript
Raw Normal View History

//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 = [];
};
var p = Result.prototype;
2013-01-21 21:38:04 +08:00
var matchRegexp = /([A-Za-z]+) (\d+ )?(\d+)?/;
//adds a command complete message
p.addCommandComplete = function(msg) {
2013-01-21 21:38:04 +08:00
var match;
if(msg.text) {
//pure javascript
2013-01-21 21:38:04 +08:00
match = matchRegexp.exec(msg.text);
} else {
//native bindings
2013-01-21 21:38:04 +08:00
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
2013-01-21 21:38:04 +08:00
this.rowCount = parseInt(match[3] || msg.value, 10);
this.oid = parseInt(match[2], 10);
} else {
2013-01-21 21:38:04 +08:00
this.rowCount = parseInt(match[2], 10);
}
}
};
p.addRow = function(row) {
this.rows.push(row);
};
module.exports = Result;