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

Package detail

koa2-mysql-wrapper

JamesnaW46MIT2.0.1

Koa2 middleware for wrap Mysql2

mysql2, async, koa2-mysql2, koa2-mysql, koa2-mysql2-wrapper, mysql2-wrapper, mysql-wrapper, koa2-middleware, mysql2-middleware, mysql-async, wrapper

readme

Koa2-mysql-wrapper

Koa2 middleware for wrap Mysql2

This middleware is just wrap Mysql2 project into koa context

Koa2-mysql-wrapper requires node v7.6.0 or higher for ES2015 and async function support.

Install Koa2-mysql-wrapper

npm install --save koa2-mysql-wrapper

Install Koa2-mysql-wrapper for earlier node v7.6.0 supported

npm install --save koa2-mysql-wrapper@1

mysql(connectionString, [options])

  • connectionString: Mysql2 connection string, e.g. {host:'localhost', user: 'root', password: 'test', database: 'test'}
  • options: Object, You can overwrite method to call this wrapper method, default you will call like ctx.myPool().query, overwrite by pass { method: 'mysql' }, so you can call ctx.mysql.query()

query(queryString, argument, options)

  • queryString: select * from user.
  • argument: Default = [], replace value on ? prefix, select * from user where active=?, [true]
  • options: Object, if you need column name then you can pass option { field: true }. Default { field: false }

Usage

import Koa from 'koa'
import mysql from 'koa2-mysql-wrapper'

const app = new Koa()

app.use(mysql({host:'localhost', user: 'root', password: 'test', database: 'test'}))

app.use(async (ctx, next) => {
  let query = await ctx.myPool().query('SELECT * FROM `table` WHERE `name` = ? AND `dead` = ?', ['James', 0])
  await next()
})

Supported

  • Array values: ctx.myPool().query('SELECT * FROM table WHERE name in (?) AND dead = ?', [['James', 'Collyer'], 0]), notice that its support only 1 nested array.

Thanks to supported me, If you find any issue or need any special modules please report me to improve and maintenance for better module.

License

MIT

changelog

[2.0.1] - 2017-03-23

Updated

  • Updated README.md (Wrong example, sorry its my fault.)

[2.0.0] - 2017-03-08

Changed

  • Koa2-mysql-wrapper requires node v7.6.0 or higher for ES2015 and async function support.
  • Updated mysql2 version from 1.1.2 to 1.2.0

[1.1.5] - 2017-03-08

Add

  • Add query options

    Remove

  • Remove convert boolean to number feature

[1.1.4] - 2017-02-21

Fixed

  • Fix error when pass only 1 argument

[1.1.3] - 2017-02-21

Add

  • Add CHANGELOG.md

    Fixed

  • Fix error when pass only 1 argument