Skip to content

Instantly share code, notes, and snippets.

@edwin-bluekite
Created October 2, 2014 14:09
Show Gist options
  • Save edwin-bluekite/e5233890244eacd0a3ed to your computer and use it in GitHub Desktop.
Save edwin-bluekite/e5233890244eacd0a3ed to your computer and use it in GitHub Desktop.
Mysql Numbers Module
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : 'adj',
database : 'xoomphones'
});
module.exports = {
nextNumber: function(callback) {
connection.query('select id,number from number where taken is null and number != \'<null>\' limit 1;', function(err, rows, fields) {
connection.query("UPDATE number SET taken = ? WHERE id = ?", [1, rows[0].id],function(err, results){
if (err) throw err;
connection.end();
});
if (err) throw err;
console.log('The number is: ', rows[0].number, 'ID:', rows[0].id);
callback(rows[0].number, rows[0].id);
});
},
updateNumber : function(slug, balance, accoundId, id, callback) {
connection.query("UPDATE number SET slug = ?, balance = ? WHERE id = ?", [slug, balance, id],function(err, results){
if (err) throw err;
connection.end();
callback(accountId);
});
},
connect:function(){
connection.connect();
},
end:function(){
connection.end();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment