Skip to content

lagden/mysql-pool

Repository files navigation

mysql-pool

NPM version Build Status Coverage Status

Make pooling connections with MySQL

Install

$ npm i @tadashi/mysql-pool

Environment variable

Variable Type Required Default Description
MYHOST string no localhost Hostname or server address
MYPORT number no 3306 Port number for the connection
MYUSER string no root User authentication
MYPASS string no Authentication password
MYLIMIT number no 5 Limit or threshold value
MYCONNECTTIMEOUT number no 30000 Connection timeout in milliseconds
MYACQUIRETIMEOUT number no 30000 Resource acquisition timeout in milliseconds
MYMULTIPLE boolean no true Allowing multiple statements
MYWAITFORCONNECTIONS boolean no true Waiting for available connections
MYENCODE number no 0 MYUSER and MYPASS encoded in base64

Usage

import MysqlPool from '@tadashi/mysql-pool'

const pool = new MysqlPool() // => https://github.com/mysqljs/mysql#connection-options
const {results: [{total}]} = await pool.query('SELECT 1 + ? as total', [1])
// => 2

// Closing all the connections in a pool
await pool.end()

License

MIT © Thiago Lagden