Skip to content

Instantly share code, notes, and snippets.

@tomasikp
Created April 2, 2013 07:29
Show Gist options
  • Save tomasikp/5290531 to your computer and use it in GitHub Desktop.
Save tomasikp/5290531 to your computer and use it in GitHub Desktop.
Used to generate charsets for node-mysql
var mysql = require('mysql');
var fs = require('fs');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root'
});
connection.connect();
connection.query('SELECT collation_name, id FROM information_schema.collations ORDER BY id', function(err, rows, fields) {
if (err) throw err;
var data = "";
var currentRow = "";
for(var x=0; x<rows.length; x++)
{
currentRow = "exports."+rows[x].collation_name.toUpperCase();
while((currentRow.length-30)<0)
{
currentRow+=" ";
}
currentRow+=(" = "+ rows[x].id + ";\n");
data+=currentRow;
}
fs.writeFile('charsets.js', data,function(err){
});
});
connection.end();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment