mysql-queue-pool

0.2.0 • Public • Published

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);
  1. 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'
  });

Readme

Keywords

none

Package Sidebar

Install

npm i mysql-queue-pool

Weekly Downloads

0

Version

0.2.0

License

BSD

Last publish

Collaborators

  • rpycka