Promise-mysql
Promise-mysql is a wrapper for mysqljs/mysql that wraps function calls with Bluebird promises.
API
mysql.createConnection(connectionOptions)
This will return a the promise of a connection object.Parameters
connectionOptions
object: A connectionOptions objectReturn value
A BluebirdPromise
that resolves to a connection objectmysql.createPool(poolOptions)
This will return a the promise of a pool object.Parameters
poolOptions
object: A poolOptions objectReturn value
A BluebirdPromise
that resolves to a pool objectmysql.createPoolCluster(poolClusterOptions)
This will return a the promise of a poolCluster object.Parameters
poolClusterOptions
object: A poolClusterOptions objectReturn value
A BluebirdPromise
that resolves to a poolCluster objectconnectionOptions object
In addition to the connection options in mysqljs/mysql, 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. 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 objectcallback(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 documentationconnection.queryStream
: Perform a query, but return the query object for streaming. See mysqljs/mysql documentationconnection.beginTransaction
: Begin a transaction. See mysqljs/mysql documentationconnection.commit
: Commit a transaction. See mysqljs/mysql documentationconnection.rollback
: Roll back a transaction. See mysqljs/mysql documentationconnection.changeUser
: Change the current connected user. See mysqljs/mysql documentationconnection.ping
: Send a ping to the server. See mysqljs/mysql documentationconnection.end
: End the connection. See mysqljs/mysql documentationconnection.destroy
: Destroy the connection. See mysqljs/mysql documentationconnection.pause
: Pause a connection. See mysqljs/mysql documentationconnection.resume
: Resume a connection. See mysqljs/mysql documentationconnection.escape
: Escape query values. See mysqljs/mysql documentationconnection.escapeId
: Escape query identifiers. See mysqljs/mysql documentationconnection.format
: Prepare a query. See mysqljs/mysql documentationconnection.on
: Add a listener to the connection object. See mysqljs/mysql documentation for events that may be listened for.poolOptions object
In addition to the pool options in mysqljs/mysql, 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. 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 objectcallback(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 from the pool. See mysqljs/mysql documentationpool.query
: Get a connection from the pool, run a query and then release it back into the pool. See mysqljs/mysql documentationpool.end
: End all the connections in a pool. See mysqljs/mysql documentationpool.escape
: Escape query values. See mysqljs/mysql documentationpool.escapeId
: Escape query identifiers. See mysqljs/mysql documentationpool.on
: Add a listener to the pool object. See mysqljs/mysql documentation for events that may be listened for.poolConnection object methods
In addition to the methods in the connection object, poolConnections also has the following method:poolConnection.release
: Release a connection back to the pool. See mysqljs/mysql documentationpoolClusterOptions object
The options used to create a pool cluster. See mysqljs/mysql documentationpoolCluster object methods
poolCluster.add
: Adds a pool configuration. See mysqljs/mysql documentationpoolCluster.remove
: Removes pool configurations. See mysqljs/mysql documentationpoolCluster.getConnection
: Get a poolConnection from the pool cluster. See mysqljs/mysql documentationpoolCluster.of
: Get a pool from the pool cluster. See mysqljs/mysql documentationpoolCluster.end
: End all the connections in a pool cluster. See mysqljs/mysql documentationpoolCluster.on
: Add a listener to the pool cluster object. See mysqljs/mysql documentation for events that may be listened for.Upgrading from v3 to v4
The main difference is thatmysql.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.Upgrading from v4 to v5
Thepool.releaseConnection
has been removed, please use poolConnection.release
instead.