1.0.0 • Published 4 years ago

runsv-mysql-pool v1.0.0

Weekly downloads
-
License
MIT
Repository
gitlab
Last release
4 years ago

runsv-mysql-pool

pipeline status coverage report

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 A String. Default is "mysql".
1.0.0

4 years ago