runsv-mysql-pool
v1.0.0
Published
runsv service wrapper around mysql module
Downloads
2
Readme
runsv-mysql-pool
runsv service wrapper around the great mysql module.
Install
If you have already installed mysql
$ npm install runsv-mysql-pool
Otherwise
$ npm install mysql runsv-mysql-pool
mysql is a peer dependency of this module
Usage
Create a MySQL connection pool
const runsv = require('runsv')();
// Pool options. Same as https://www.npmjs.com/package/mysql#pool-options
const poolOptions = { /*...*/}
const createMySQLPoolService = require('runsv-mysql-pool');
const poolClientName = 'myPool';
const poolService = createMySQLPoolService(poolOptions, poolClientName);
runsv.addService(mysql);
runsv.start(function(err){
const {myPool} = runsv.getClients();
// myPool is the same object you will get with mysql.createPool(...)
myPool.query('SELECT ...', function (err, rows) {
/* ... */
});
});
/* ... other application logic */
API
createMySQLPoolService(options, name='mysql')
this function will create the service wrapper.#options
Same as the mysql ones#name
AString
. Default is "mysql".