p-mysql-middleware

0.0.2 • Public • Published

Node-MySQL-Middleware

Middleware for filling every request with a MySQL connection pool instance wrapper.

Middleware accepts 2 arguments - options and key:

var database = require('p-mysql-middleware')

app.use(database(options, 'con'))
  • options argument is directly passed to MySQL driver module's createPool method so it accepts all the same parameters.

  • key argument is database instance key in request object. Defaults to 'database'.

With the example above, database instance can be accessed as req.con where req is the request object.

Database instance supports only one method - query which acquires database connection from the pool and queries the query. It is supposed to work as the original connection's query method:

req.con.query('SELECT * FROM users', function(error, rows) { /* ... */ })
req.con.query('SELECT * FROM users WHERE username=?', [ 'nom_nom' ], function(error, rows, cols) { /* ... */ })

/p-mysql-middleware/

    Package Sidebar

    Install

    npm i p-mysql-middleware

    Weekly Downloads

    0

    Version

    0.0.2

    License

    MIT

    Last publish

    Collaborators

    • pius