Skip to content

Instantly share code, notes, and snippets.

@ronaldb
Created July 3, 2014 03:51
Show Gist options
  • Save ronaldb/2138545ba2f7663db536 to your computer and use it in GitHub Desktop.
Save ronaldb/2138545ba2f7663db536 to your computer and use it in GitHub Desktop.
Sample mariadb query with nodejs
var mariasql = require('mariasql');
var inspect = require('util').inspect;
var result = '';
var dbclient = new mariasql();
dbclient.connect({user: 'username',
password: 'password',
database: 'dlb',
host: 'localhost'});
dbclient.query('SELECT * FROM dlb.SONGLIST LIMIT 5')
.on('result', function(res) {
res.on('row', function(row) {
console.log('Query result:', inspect(row));
result += row.id + ',';
})
res.on('end', function(info) {
console.log('Query ended - ',result);
console.log('Info object:', inspect(info));
})
res.on('error', function(err) {
console.log('Result error: ' + inspect(err));
throw(err);
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment