mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
Rows are now associative arrays rather than straight arrays.
This commit is contained in:
parent
1237db1f4a
commit
721cf56eb3
BIN
lib/.query.js.swp
Normal file
BIN
lib/.query.js.swp
Normal file
Binary file not shown.
@ -43,7 +43,7 @@ p.submit = function(connection) {
|
||||
};
|
||||
};
|
||||
var handleDatarow = function(msg) {
|
||||
var result = [];
|
||||
var result = {};
|
||||
for(var i = 0; i < msg.fields.length; i++) {
|
||||
var rawValue = msg.fields[i];
|
||||
result[names[i]] = rawValue === null ? null : converters[i](rawValue);
|
||||
|
||||
@ -4,7 +4,7 @@ test("simple query interface", function() {
|
||||
|
||||
var client = helper.client();
|
||||
|
||||
var query = client.query("select name from person");
|
||||
var query = client.query("select name from person order by name");
|
||||
|
||||
client.on('drain', client.end.bind(client));
|
||||
|
||||
@ -12,6 +12,17 @@ test("simple query interface", function() {
|
||||
query.on('row', function(row) {
|
||||
rows.push(row['name'])
|
||||
});
|
||||
query.once('row', function(row) {
|
||||
test('Can iterate through columns', function () {
|
||||
var columnCount = 0;
|
||||
for (column in row) {
|
||||
columnCount++;
|
||||
};
|
||||
if ('length' in row) {
|
||||
assert.length(row, columnCount, 'Iterating through the columns gives a different length from calling .length.');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
assert.emits(query, 'end', function() {
|
||||
test("returned right number of rows", function() {
|
||||
|
||||
@ -10,6 +10,17 @@ module.exports = {
|
||||
host: helper.args.host,
|
||||
port: helper.args.port
|
||||
});
|
||||
client.on('error', function(e, d) {
|
||||
console.log(e);
|
||||
});
|
||||
var rawQuery = client.query;
|
||||
client.query = function() {
|
||||
var q = rawQuery.apply(this, arguments);
|
||||
q.on('error', function(e) {
|
||||
console.log(e);
|
||||
});
|
||||
return q;
|
||||
};
|
||||
client.connect();
|
||||
return client;
|
||||
},
|
||||
|
||||
@ -10,6 +10,15 @@ buffers = require(__dirname + '/test-buffers');
|
||||
Connection = require('connection');
|
||||
var args = require(__dirname + '/cli');
|
||||
|
||||
process.on('uncaughtException', function(d) {
|
||||
if ('stack' in d && 'message' in d) {
|
||||
console.log("Message: " + d.message);
|
||||
console.log(d.stack);
|
||||
} else {
|
||||
console.log(d);
|
||||
}
|
||||
});
|
||||
|
||||
assert.same = function(actual, expected) {
|
||||
for(var key in expected) {
|
||||
assert.equal(actual[key], expected[key]);
|
||||
@ -102,6 +111,7 @@ assert.isNull = function(item, message) {
|
||||
|
||||
test = function(name, action) {
|
||||
test.testCount ++;
|
||||
console.log('\n' + name);
|
||||
var result = action();
|
||||
if(result === false) {
|
||||
test.ignored.push(name);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user