npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

promise-mysql

v5.2.0

Published

A bluebird wrapper for node-mysql

Downloads

138,964

Readme

Promise-mysql

Build Status Greenkeeper badge

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 object

Return value

A Bluebird Promise that resolves to a connection object

mysql.createPool(poolOptions)

This will return a the promise of a pool object.

Parameters

poolOptions object: A poolOptions object

Return value

A Bluebird Promise that resolves to a pool object

mysql.createPoolCluster(poolClusterOptions)

This will return a the promise of a poolCluster object.

Parameters

poolClusterOptions object: A poolClusterOptions object

Return value

A Bluebird Promise that resolves to a poolCluster object

connectionOptions 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 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

connection.queryStream: Perform a query, but return the query object for streaming. See mysqljs/mysql documentation

connection.beginTransaction: Begin a transaction. See mysqljs/mysql documentation

connection.commit: Commit a transaction. See mysqljs/mysql documentation

connection.rollback: Roll back a transaction. See mysqljs/mysql documentation

connection.changeUser: Change the current connected user. See mysqljs/mysql documentation

connection.ping: Send a ping to the server. See mysqljs/mysql documentation

connection.end: End the connection. See mysqljs/mysql documentation

connection.destroy: Destroy the connection. See mysqljs/mysql documentation

connection.pause: Pause a connection. See mysqljs/mysql documentation

connection.resume: Resume a connection. See mysqljs/mysql documentation

connection.escape: Escape query values. See mysqljs/mysql documentation

connection.escapeId: Escape query identifiers. See mysqljs/mysql documentation

connection.format: Prepare a query. See mysqljs/mysql documentation

connection.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 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 from the pool. See mysqljs/mysql documentation

pool.query: Get a connection from the pool, run a query and then release it back into the pool. See mysqljs/mysql documentation

pool.end: End all the connections in a pool. See mysqljs/mysql documentation

pool.escape: Escape query values. See mysqljs/mysql documentation

pool.escapeId: Escape query identifiers. See mysqljs/mysql documentation

pool.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 documentation

poolClusterOptions object

The options used to create a pool cluster. See mysqljs/mysql documentation

poolCluster object methods

poolCluster.add: Adds a pool configuration. See mysqljs/mysql documentation

poolCluster.remove: Removes pool configurations. See mysqljs/mysql documentation

poolCluster.getConnection: Get a poolConnection from the pool cluster. See mysqljs/mysql documentation

poolCluster.of: Get a pool from the pool cluster. See mysqljs/mysql documentation

poolCluster.end: End all the connections in a pool cluster. See mysqljs/mysql documentation

poolCluster.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 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.

Upgrading from v4 to v5

The pool.releaseConnection has been removed, please use poolConnection.release instead.