0.2.0 • Published 12 years ago
mysql-queue-pool v0.2.0
Node's MySQL's Queue's Pool
Small library that offers db connection pool management and simple query-queue flattener (streamliner?).
Works with node-mysql (https://github.com/felixge/node-mysql) module;
- Author: Radek Pycka
- License: BSD
Usage
1) Pool configuration:
var DBM = require('mysql-queue-pool').Manager;
var dbconf = {
host: 'localhost',
user: 'user',
password: 'pass',
database: 'test'
};
DBM.register(dbconf, DBM.DEFAULT_POOL_NAME, 10);
2) Running queries:
Import:
var runQuery = require('mysql-queue-pool').runQuery;
Invoke (crude user authentication):
var username = 'tester';
runQuery({
steps: [
{
query: 'SELECT * FROM users WHERE name = ? LIMIT 1',
args: [ username ],
success: function (rows) {
if (rows[0].password === this.config.userpass) {
this.nextArgs('#session id#', rows[0].id);
}
else {
this.fail('Password didn\'t make it :(');
}
}
},
{
query: 'UPDATE users SET sid = ? WHERE id = ? LIMIT 1',
success: function (result) {
console.log('Session started!');
}
}
],
failure: authSqlErrHandler,
userpass: 'strong password'
});