# promise-mysql

> A bluebird wrapper for node-mysql

Latest version **5.2.0** (published 2022-04-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install promise-mysql
pnpm add promise-mysql
yarn add promise-mysql
bun add promise-mysql
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 5.2.0 |
| Published | 2022-04-30 |
| First published | 2014-10-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 25 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 333 |
| Author | Luke Bonaccorsi |
| Maintainers | lukeb |
| Keywords | promise, performance, promises, promises-a, promises-aplus, async, await, deferred, deferreds, future, flow control, dsl, fluent interface, database, mysql, mysql-promise, bluebird, q |

## Links

- npm: https://www.npmjs.com/package/promise-mysql
- Repository: https://github.com/lukeb-uk/node-promise-mysql
- Homepage: https://github.com/lukeb-uk/node-promise-mysql#readme
- Issues: https://github.com/lukeb-uk/node-promise-mysql/issues
- npm.io page: https://npm.io/package/promise-mysql

## Dependencies (4)

- [mysql](https://npm.io/package/mysql.md) ^2.18.1
- [bluebird](https://npm.io/package/bluebird.md) ^3.5.1
- [@types/mysql](https://npm.io/package/@types/mysql.md) ^2.15.2
- [@types/bluebird](https://npm.io/package/@types/bluebird.md) ^3.5.26

## Alternatives

- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads
- [fa](https://npm.io/package/fa.md) — 185 weekly downloads

## Recent versions

- 5.2.0 (latest) — 2022-04-30
- 4.0.0-beta.0 (beta) — 2019-05-19
- 5.1.0 — 2022-01-10
- 5.0.4 — 2021-09-16
- 5.0.3 — 2021-02-25
- 5.0.2 — 2021-01-15
- 5.0.1 — 2020-12-10
- 5.0.0 — 2020-12-08
- 4.1.4 — 2020-12-02
- 4.1.3 — 2020-02-04
- 4.1.2 — 2020-01-27
- 4.1.1 — 2019-10-08
- 4.1.0 — 2019-07-13
- 4.0.4 — 2019-06-20
- 4.0.3 — 2019-06-14
- … 30 more at https://npm.io/package/promise-mysql/versions

## README

Promise-mysql
==================
[![Build Status](https://travis-ci.org/lukeb-uk/node-promise-mysql.svg?style=flat&branch=master)](https://travis-ci.org/lukeb-uk/node-promise-mysql?branch=master)
[![Greenkeeper badge](https://badges.greenkeeper.io/lukeb-uk/node-promise-mysql.svg)](https://greenkeeper.io/)

Promise-mysql is a wrapper for [mysqljs/mysql](https://github.com/mysqljs/mysql) that wraps function calls with [Bluebird](https://github.com/petkaantonov/bluebird/) promises.

## API

### mysql.createConnection(connectionOptions)
This will return a the promise of a [connection](#connection-object-methods) object.

#### Parameters
`connectionOptions` _object_: A [connectionOptions](#connectionoptions-object) object

#### Return value
A Bluebird `Promise` that resolves to a [connection](#connection-object-methods) object

### mysql.createPool(poolOptions)
This will return a the promise of a [pool](#pool-object-methods) object.

#### Parameters
`poolOptions` _object_: A [poolOptions](#pooloptions-object) object

#### Return value
A Bluebird `Promise` that resolves to a [pool](#pool-object-methods) object

### mysql.createPoolCluster(poolClusterOptions)
This will return a the promise of a [poolCluster](#poolcluster-object-methods) object.

#### Parameters
`poolClusterOptions` _object_: A [poolClusterOptions](#poolclusteroptions-object) object

#### Return value
A Bluebird `Promise` that resolves to a [poolCluster](#poolcluster-object-methods) object

### connectionOptions object

In addition to the [connection options in mysqljs/mysql](https://github.com/mysqljs/mysql#connection-options), promise-mysql accepts the following:

`returnArgumentsArray` _boolean_: If set to true then methods will return an array with the callback arguments from the underlying method (excluding the any errors) and the return value from the call.

`mysqlWrapper` _function_: A function that is passed the `mysql` object so that it can be wrapped with something like the [aws-xray-sdk module](https://www.npmjs.com/package/aws-xray-sdk). This function must either return the wrapped `mysql` object, return a promise of the wrapped `mysql` object or call the callback that is passed into the function.

`reconnect` _boolean_ (default: true): If set to true then the connection will reconnect on the `PROTOCOL_CONNECTION_LOST`, `ECONNRESET` and `PROTOCOL_ENQUEUE_AFTER_FATAL_ERROR` errors.

#### Function arguments

`mysql` _mysql object_: The mysql object

`callback(error, success)` _function_: A node-style callback that can be used to pass the wrapped version of the mysql object out of the wrapper function.

### Connection object methods

`connection.query`: Perform a query. See [mysqljs/mysql documentation](https://github.com/mysqljs/mysql#performing-queries)

`connection.queryStream`: Perform a query, but return the query object for streaming. See [mysqljs/mysql documentation](https://github.com/mysqljs/mysql#streaming-query-rows)

`connection.beginTransaction`: Begin a transaction. See [mysqljs/mysql documentation](https://github.com/mysqljs/mysql#transactions)

`connection.commit`: Commit a transaction. See [mysqljs/mysql documentation](https://github.com/mysqljs/mysql#transactions)

`connection.rollback`: Roll back a transaction. See [mysqljs/mysql documentation](https://github.com/mysqljs/mysql#transactions)

`connection.changeUser`: Change the current connected user. See [mysqljs/mysql documentation](https://github.com/mysqljs/mysql#switching-users-and-altering-connection-state)

`connection.ping`: Send a ping to the server. See [mysqljs/mysql documentation](https://github.com/mysqljs/mysql#ping)

`connection.end`: End the connection. See [mysqljs/mysql documentation](https://github.com/mysqljs/mysql#terminating-connections)

`connection.destroy`: Destroy the connection. See [mysqljs/mysql documentation](https://github.com/mysqljs/mysql#terminating-connections)

`connection.pause`: Pause a connection. See [mysqljs/mysql documentation](https://github.com/mysqljs/mysql#streaming-query-rows)

`connection.resume`: Resume a connection. See [mysqljs/mysql documentation](https://github.com/mysqljs/mysql#streaming-query-rows)

`connection.escape`: Escape query values. See [mysqljs/mysql documentation](https://github.com/mysqljs/mysql#escaping-query-values)

`connection.escapeId`: Escape query identifiers. See [mysqljs/mysql documentation](https://github.com/mysqljs/mysql#escaping-query-identifiers)

`connection.format`: Prepare a query. See [mysqljs/mysql documentation](https://github.com/mysqljs/mysql#preparing-queries)

`connection.on`: Add a listener to the connection object. See [mysqljs/mysql documentation](https://github.com/mysqljs/mysql) for events that may be listened for.

### poolOptions object

In addition to the [pool options in mysqljs/mysql](https://www.npmjs.com/package/mysql#pool-options), promise-mysql accepts the following:

`returnArgumentsArray` _boolean_: If set to true then methods will return an array with the callback arguments from the underlying method (excluding the any errors) and the return value from the call.

`mysqlWrapper` _function_: A function that is passed the `mysql` object so that it can be wrapped with something like the [aws-xray-sdk module](https://www.npmjs.com/package/aws-xray-sdk). This function must either return the wrapped `mysql` object, return a promise of the wrapped `mysql` object or call the callback that is passed into the function.

#### Function arguments

`mysql` _mysql object_: The mysql object

`callback(error, success)` _function_: A node-style callback that can be used to pass the wrapped version of the mysql object out of the wrapper function.

### Pool object methods

`pool.getConnection`: Get a [poolConnection](#poolconnection-object-methods) from the pool. See [mysqljs/mysql documentation](https://github.com/mysqljs/mysql#pooling-connections)

`pool.query`: Get a connection from the pool, run a query and then release it back into the pool. See [mysqljs/mysql documentation](https://github.com/mysqljs/mysql#pooling-connections)

`pool.end`: End all the connections in a pool. See [mysqljs/mysql documentation](https://github.com/mysqljs/mysql#closing-all-the-connections-in-a-pool)

`pool.escape`: Escape query values. See [mysqljs/mysql documentation](https://github.com/mysqljs/mysql#escaping-query-values)

`pool.escapeId`: Escape query identifiers. See [mysqljs/mysql documentation](https://github.com/mysqljs/mysql#escaping-query-identifiers)

`pool.on`: Add a listener to the pool object. See [mysqljs/mysql documentation](https://github.com/mysqljs/mysql#pool-events) for events that may be listened for.

### poolConnection object methods

In addition to the [methods in the connection object](#connection-object-methods), poolConnections also has the following method:

`poolConnection.release`: Release a connection back to the pool. See [mysqljs/mysql documentation](https://www.npmjs.com/package/mysql#pooling-connections)

### poolClusterOptions object

The options used to create a pool cluster. See [mysqljs/mysql documentation](https://www.npmjs.com/package/mysql#poolcluster-options)

### poolCluster object methods

`poolCluster.add`: Adds a pool configuration. See [mysqljs/mysql documentation](https://www.npmjs.com/package/mysql#poolcluster)

`poolCluster.remove`: Removes pool configurations. See [mysqljs/mysql documentation](https://www.npmjs.com/package/mysql#poolcluster)

`poolCluster.getConnection`: Get a [poolConnection](#poolconnection-object-methods) from the pool cluster. See [mysqljs/mysql documentation](https://www.npmjs.com/package/mysql#poolcluster)

`poolCluster.of`: Get a pool from the pool cluster. See [mysqljs/mysql documentation](https://www.npmjs.com/package/mysql#poolcluster)

`poolCluster.end`: End all the connections in a pool cluster. See [mysqljs/mysql documentation](https://github.com/mysqljs/mysql#pooling-connections)

`poolCluster.on`: Add a listener to the pool cluster object. See [mysqljs/mysql documentation](https://github.com/mysqljs/mysql#poolcluster) for events that may be listened for.

## Upgrading from v3 to v4
The main difference is that `mysql.createPool` now returns a promise. Besides this, the API is the same and you should be able to upgrade straight to v4. The only other difference is the extra options in the [connectionOptions object](#connectionoptions-object).

## Upgrading from v4 to v5
The `pool.releaseConnection` has been removed, please use `poolConnection.release` instead.

---
_Source: https://npm.io/package/promise-mysql · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
