mysql-queue-pool
v0.2.0
Published
Database connection pooling and query queueing.
Downloads
3
Readme
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
- 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);
- 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'
});