mysql-queue-pool

Database connection pooling and query queueing.

npm install mysql-queue-pool
12 downloads in the last month

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

Installation

$ npm install mysql-queue-pool

Usage

1) Pool configuration:

var DBM = require('mysql-queue-pool').DBM;

var dbconf = {
  name: 'default'
  adapter: 'mysql',
  poolmax: 10,

  host: 'localhost',
  user: 'user',
  password: 'pass',
  database: 'test'
};

DBM.register(dbconf);

2) Running queries:

Import:

var query = require('mysql-queue-pool').query;

Invoke (crude user authentication):

  var username = 'tester';

  query({
    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'
  });
npm loves you