Return field metadata on result object
Closes #209 Native implementation requires significant refactor and so I wont work on this if/until there is an issue for it
This commit is contained in:
parent
7c12630d11
commit
337d49dddb
@ -63,6 +63,7 @@ Query.prototype.handleRowDescription = function(msg) {
|
||||
var format = field.format;
|
||||
this._fieldNames[i] = field.name;
|
||||
this._fieldConverters[i] = Types.getTypeParser(field.dataTypeID, format);
|
||||
this._result.addField(field);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -6,6 +6,7 @@ var Result = function() {
|
||||
this.rowCount = null;
|
||||
this.oid = null;
|
||||
this.rows = [];
|
||||
this.fields = [];
|
||||
};
|
||||
|
||||
var matchRegexp = /([A-Za-z]+) ?(\d+ )?(\d+)?/;
|
||||
@ -37,4 +38,9 @@ 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;
|
||||
|
23
test/integration/client/no-row-result-tests.js
Normal file
23
test/integration/client/no-row-result-tests.js
Normal file
@ -0,0 +1,23 @@
|
||||
var helper = require(__dirname + '/test-helper');
|
||||
var pg = helper.pg;
|
||||
var config = helper.config;
|
||||
|
||||
test('can access results when no rows are returned', function() {
|
||||
if(config.native) return false;
|
||||
var checkResult = function(result) {
|
||||
assert(result.fields, 'should have fields definition');
|
||||
assert.equal(result.fields.length, 1);
|
||||
assert.equal(result.fields[0].name, 'val');
|
||||
assert.equal(result.fields[0].dataTypeID, 25);
|
||||
pg.end();
|
||||
};
|
||||
|
||||
pg.connect(config, assert.success(function(client, done) {
|
||||
var query = client.query('select $1::text as val limit 0', ['hi'], assert.success(function(result) {
|
||||
checkResult(result);
|
||||
done();
|
||||
}));
|
||||
|
||||
assert.emits(query, 'end', checkResult);
|
||||
}));
|
||||
});
|
Loading…
Reference in New Issue
Block a user