Skip to content

Instantly share code, notes, and snippets.

@egorFiNE
Created June 30, 2012 09:52
Show Gist options
  • Save egorFiNE/3023193 to your computer and use it in GitHub Desktop.
Save egorFiNE/3023193 to your computer and use it in GitHub Desktop.
Fix for node-mysql BIGINT
/*
Usage:
FixMysqlBigint = require('FixMysqlBigint');
mysqlConnection.query("SELECT a,b,c FROM z", function(err, results, fieldInfo) {
if (err) {
...
}
FixMysqlBigint(results, fieldInfo);
// now all bigints were parsed to js number
});
*/
module.exports = function(results, fieldInfo) {
if (!fieldInfo || !results) {
return;
}
if (results.length<=0) {
return;
}
var bigints = [];
var i=0;
for(i=0;i<fieldInfo.length;i++) {
if (fieldInfo[i].type==8) {
bigints.push(fieldInfo[i].name);
}
}
if (bigints.length<=0) {
return;
}
results.forEach(function(entry) {
var j;
for(j=0;j<bigints.length;j++) {
entry[bigints[j]]=parseInt(entry[bigints[j]], 10);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment