Promisucous MySQL is a promise-based MySQL client built on top of the mysql module.
const database = require('promiscuous-mysql')
database.withConnection({
host: 'example.org',
user: 'bob',
password: 'secret',
database: 'my-database'
}, (connection) => {
return connection.query('SELECT * FROM `items`')
})
.then((result) => {
console.log(result)
})
Creates a new Connection
instance.
config
(Object): The connection configuration. See themysql
connection options for details.
Creates a new Connection
instance, invokes the callback with the new instance, then ends the connection.
config
(Object): The connection configuration. See themysql
connection options for details.callback
(Function:function(connection) Returns: Promise
): A callback used to perform queries with the created connection. Must return a promise indicating whether the operation was successful. The value of the promise returned from the callback will become the return value forwithConnection()
. If there is an error creating the connection, the callback will not be invoked and the returned promise will be rejected.
Creates a new Connection
instance, starts a transaction, invokes the callback, then ends the transaction and connection.
config
(Object): The connection configuration. See themysql
connection options for details.callback
(Function:function(connection) Returns: Promise
): A callback used to perform queries within the created transaction. Must return a promise indicating whether the operation was successful. If the callback's promise is resolved, the transaction will be committed; if the callback's promise is rejected, the transaction will be rolled back. The value of the promise returned from the callback will become the return value forwithTransaction()
. If there is an error creating the connection, the callback will not be invoked and the returned promise will be rejected.
Creates a new connection pool.
name
(String): The name for the pool.config
(Object): The connection configuration. See themysql
documentation for connection options for details.
Creates a new Connection
instance, invokes the callback with the new instance, then ends the connection.
name
(String): The name of the pool to use.callback
(Function:function(connection) Returns: Promise
): A callback used to perform queries with the created connection. Must return a promise indicating whether the operation was successful. The value of the promise returned from the callback will become the return value forwithPooledConnection()
. If there is an error creating the connection, the callback will not be invoked and the returned promise will be rejected.
Creates a new Connection
instance, starts a transaction, invokes the callback, then ends the transaction and connection.
name
(String): The name for the pool.callback
(Function:function(connection) Returns: Promise
): A callback used to perform queries within the created transaction. Must return a promise indicating whether the operation was successful. If the callback's promise is resolved, the transaction will be committed; if the callback's promise is rejected, the transaction will be rolled back. The value of the promise returned from the callback will become the return value forwithPooledTransaction()
. If there is an error creating the connection, the callback will not be invoked and the returned promise will be rejected.
Performs a query using the existing connection. See the mysql
documentation for performing queries. All signatures are supported, just leave out the callback.
Ends the connection.
Ends the connection pool.
Copyright Promiscuous MySQL contributors. Released under the terms of the ISC license.