Created
June 30, 2012 09:52
-
-
Save egorFiNE/3023193 to your computer and use it in GitHub Desktop.
Fix for node-mysql BIGINT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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