Skip to content

rikmms/mysql-easy-pool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mysql-easy-pool

ATTENTION: This module is deprecated and no longer under maintenance. Please check the new module mysql-promise-extension

This module exports an object to handle with the mysql connection's pool more easily. We can use the getConnection() function to get one connection for execute our queries, or we can use the getTransactionConnection() function to get one connection inside a transaction that performs the rollback action if any error occurred.

The purpose of this module is to act like a helper for the great mysql module.

Installation:

  • npm install mysql-easy-pool

Example:

  
    const MySqlEasyPool = require('mysql-easy-pool')
    const mysqlPool = new MySqlEasyPool({
    	host: process.env.HOST,
    	user: process.env.USER,
    	password: process.env.PASS,
    	database: process.env.DB
    })
  
    mysqlPool.getConnection((connection, done) => {
      // create the queries
    	connection.query(SQL STATEMENT, [...], (err, res) => {
    	  done(err, res)
    	})
    }, callback)
    
    mysqlPool.getTransactionConnection((connection, done) => {
      // create the queries
  		async.waterfall([
  			(cb) => {
  				connection.query(SQL STATEMENT ONE, [...], (err, res) => cb(err, res))
  			},
  			(res, cb) => {
  				connection.query(SQL STATEMENT TWO, [...], (err, res) => cb(err, res))
  			}
  		],
  		(err, res) => {
  			done(err, res)
  		})
  	}, callback)
  	
    > Where the callback function receives the error or the result, like: function(err, result) = { ... }

    > You can use the getter function 'pool', like "mysqlPool.pool", for set extra options to the pool.
  

Future dev:

  • Improve the documentation.
  • Able to support the PoolCluster functionality.

About

MySql connections' pool wrapper to handle the connections more easily.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •