begin type coercion for libpq
This commit is contained in:
parent
47591d677b
commit
b76ced7144
@ -136,7 +136,24 @@ var NativeQuery = function(text, values, callback) {
|
||||
sys.inherits(NativeQuery, EventEmitter);
|
||||
var p = NativeQuery.prototype;
|
||||
|
||||
p.handleRow = function(row) {
|
||||
//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];
|
||||
switch(item.type) {
|
||||
case 23:
|
||||
result[item.name] = parseInt(item.value);
|
||||
break;
|
||||
default:
|
||||
result[item.name] = item.value;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
p.handleRow = function(rowData) {
|
||||
var row = mapRowData(rowData);
|
||||
if(this.callback) {
|
||||
this.rows.push(row);
|
||||
}
|
||||
|
@ -330,11 +330,18 @@ protected:
|
||||
int rowCount = PQntuples(result);
|
||||
for(int rowNumber = 0; rowNumber < rowCount; rowNumber++) {
|
||||
//create result object for this row
|
||||
Local<Object> row = Object::New();
|
||||
Local<Array> row = Array::New();
|
||||
int fieldCount = PQnfields(result);
|
||||
for(int fieldNumber = 0; fieldNumber < fieldCount; fieldNumber++) {
|
||||
Local<Object> field = Object::New();
|
||||
char* fieldName = PQfname(result, fieldNumber);
|
||||
row->Set(String::New(fieldName), WrapFieldValue(result, rowNumber, fieldNumber));
|
||||
int fieldType = PQftype(result, fieldNumber);
|
||||
char* fieldValue = PQgetvalue(result, rowNumber, fieldNumber);
|
||||
//TODO use symbols here
|
||||
field->Set(String::New("name"), String::New(fieldName));
|
||||
field->Set(String::New("value"), String::New(fieldValue));
|
||||
field->Set(String::New("type"), Integer::New(fieldType));
|
||||
row->Set(Integer::New(fieldNumber), field);
|
||||
}
|
||||
|
||||
//not sure about what to dealloc or scope#Close here
|
||||
|
@ -38,8 +38,8 @@ for(var i = 0; i < args.length; i++) {
|
||||
case '-t':
|
||||
case '--test':
|
||||
config.test = args[++i];
|
||||
case '--libpq':
|
||||
config.libpq = (args[++i] == "true");
|
||||
case '--native':
|
||||
config.native = (args[++i] == "true");
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -1,5 +1,10 @@
|
||||
var helper = require(__dirname + '/../test-helper');
|
||||
var pg = require(__dirname + '/../../../lib');
|
||||
|
||||
if(helper.args.native) {
|
||||
pg = require(__dirname + '/../../../lib/native')
|
||||
}
|
||||
|
||||
if(helper.args.libpq) {
|
||||
pg = require(__dirname + "/../../../lib/binding");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user