<commit_before># mysql-connection-manager [![Build Status](https://travis-ci.org/chill117/mysql-connection-manager.svg?branch=master)](https://travis-ci.org/chill117/mysql-connection-manager)

Manages keep-alive signals, reconnections for a MySQL connection or connection pool.


## Installation

Add to your application via `npm`:
```
npm install mysql-connection-manager --save
```
This will install `mysql-connection-manager` and add it to your application's `package.json` file.


## How to Use

To have `mysql-connection-manager` create the connection for you:
```js
var MySQLConnectionManager = require('mysql-connection-manager')

var options = {
	host: 'localhost',
	port: 3306,
	user: 'db_user',
	password: 'password',
	database: 'db_name'
}

var manager = new MySQLConnectionManager(options)

manager.on('connect', function(connection) {

	// Connected!

})

// Pass the connection object to some other module, like this:
var something = new SomeThing(someOtherOptions, manager.connection)
```
The connection object is the same as provided by [node-mysql](https://github.com/felixge/node-mysql).

You can also pass an already existing [node-mysql](https://github.com/felixge/node-mysql) connection object to `mysql-connection-manager`, like this:
```js
var mysql = require('mysql')
var MySQLConnectionManager = require('mysql-connection-manager')

var options = {
	host: 'localhost',
	port: 3306,
	user: 'db_user',
	password: 'password',
	database: 'db_name'
}

var connection = mysql.createConnection(options)
var manager = new MySQLConnectionManager(options, connection)
```


### Options

A list of all available options:
```js
var options = {
	host: 'localhost',// Host name for database connection.
	port: 3306,// Port number for database connection.
	user: 'connect_mng_test',// Database user.
	password: 'password',// Password for the above database user.
	database: 'connect_mng_test',// Database name.<commit_msg>Additional readme info on events<commit_after># mysql-connection-manager [![Build Status](https://travis-ci.org/chill117/mysql-connection-manager.svg?branch=master)](https://travis-ci.org/chill117/mysql-connection-manager)

Manages keep-alive signals, reconnections for a MySQL connection or connection pool.


## Installation

Add to your application via `npm`:
```
npm install mysql-connection-manager --save
```
This will install `mysql-connection-manager` and add it to your application's `package.json` file.


## How to Use

To have `mysql-connection-manager` create the connection for you:
```js
var MySQLConnectionManager = require('mysql-connection-manager')

var options = {
	host: 'localhost',
	port: 3306,
	user: 'db_user',
	password: 'password',
	database: 'db_name'
}

var manager = new MySQLConnectionManager(options)

manager.on('connect', function(connection) {

	// Connected!

})

// Pass the connection object to some other module, like this:
var something = new SomeThing(someOtherOptions, manager.connection)
```
The connection object is the same as provided by [node-mysql](https://github.com/felixge/node-mysql).

You can also pass an already existing [node-mysql](https://github.com/felixge/node-mysql) connection object to `mysql-connection-manager`, like this:
```js
var mysql = require('mysql')
var MySQLConnectionManager = require('mysql-connection-manager')

var options = {
	host: 'localhost',
	port: 3306,
	user: 'db_user',
	password: 'password',
	database: 'db_name'
}

var connection = mysql.createConnection(options)
var manager = new MySQLConnectionManager(options, connection)
```


### Events

There are a few events that can be listened for on the `manager` object:
```js
manager.on('connect', function(connection) {

	// A database connection has been established..

})

manager.on('reconnect', function(connection) {

	// The database connection has been re-established..

})

manager.on('disconnect', function() {

	// The database connection has been lost..

})
```
The `manager` object is extended with the [nodejs EventEmitter](http://nodejs.org/api/events.html), so you can use all of the methods that it provides as well: `on`, `off`, `once`, `emit`, etc.


### Options

A list of all available options:
```js
var options = {
	host: 'localhost',// Host name for database connection.
	port: 3306,// Port number for database connection.
	user: 'connect_mng_test',// Database user.
	password: 'password',// Password for the above database user.
	database: 'connect_mng_test',// Database name.
{'fraction_non_alphanumeric': 0.12914055505819158, 'fraction_numerical': 0.008057296329453895, 'mean_word_length': 5.006720430107527, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2292789', 'n_tokens_mistral': 1364, 'n_tokens_neox': 1287, 'n_words': 426}