sidorares/nodejs-mysql-native — Issue #47: Result as array of Objects [feature request]
Author: Dunadan
Created: 2011-11-07 15:38:34+00:00
State: open

My own bicycle for handy resultset, where builder is mysql.query(...), cb - callback.

function mysql_result(builder, cb)
{
var field_template = new Array;
var results	= new Array;

builder
.on('field', function(f) { field_template[field_template.length] = f.name; })
.on('row', function(r) {

var m = new Object;

for(key in r)
{
value = r[key];
m[field_template[key]] = value;
}

results.push(m);
})
.on('end', function() { cb(results) });
}