Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

knex-mysql-middleware

wilmoore14MIT0.4.1

Set a MySQL flavored Knex connection that can be accessed via Koa or Express middleware.

ecosystem:koa, ecosystem:express, ecosystem:knex, dotenv, envc, knex, mysql, database, middleware, koa, express

readme

knex-mysql-middleware

Build Status NPM version NPM downloads LICENSE

Set a MySQL flavored Knex connection that can be accessed via Koa or Express middleware.

$ npm install knex-mysql-middleware

Usage

Quick Start (koa or express)
// koa
var knex = require('knex-mysql-middleware');
var app = require('koa')();
app.use(knex());

app.use(function *() {
  this.status = (yield this.knex('resource').where('id', this.query.id)) ? 204 : 404;
});

// express
var knex = require('knex-mysql-middleware/express');
var app = require('express')();
app.use(knex());

app.use(function () {
  this.status = this.knex('resource').where('id', req.query.id) ? 204 : 404;
});

Options

It is recommended that you set the parameters via environment variables and utilize a .env file via a library such as envc, dotenv, or an equivalent.

DATABASE_NAME=demo
DATABASE_USER=scott
DATABASE_PASS=tiger
DATABASE_HOST=127.0.0.1
DATABASE_PORT=3306

# optional
DATABASE_SSL=true
DATABASE_DEBUG=true
DATABASE_POOL_MIN=0
DATABASE_POOL_MAX=7
Configuration via options object
var config = {
  connection: {
    host     : '127.0.0.1',
    user     : 'scott',
    password : 'tiger',
    database : 'demo'
  },
  // optional
  debug: true,
  pool: {
    min: 0,
    max: 7
  },
  ssl: true
}

app.use(knex(config));

Alternatives

License

MIT