nodejs-mysql
The wrapper of Node.js MySQL driver with Promise enabled.
const db = mysql db )
Installation
$ npm install nodejs-mysql
Demo
Folder demo
includes a simple demo of both ES5 and ES6.
How to Use
Use config object to describe database connection(s).
// single database connectionconst config = host: '192.168.0.100' port: 3306 user: 'root' password: 'password' database: 'testdb' // database connection poolconst config = host: '192.168.0.101' port: 3306 user: 'root' password: 'password' database: 'testdb' dateStrings: true debug: false host: '192.168.0.102' port: 3306 user: 'root' password: 'password' database: 'testdb' dateStrings: true debug: false host: '192.168.0.103' port: 3306 user: 'root' password: 'password' database: 'testdb' dateStrings: true debug: false
Get instance in anywhere before do database operations.
const db = mysql
Attention If you are not using ES6, import package like this,
const mysql = default;
Method exec
for all database operation, close database connection is not need.
// selectdb // insertdb // updatedb // deletedb
nodejs-mysql
also support transaction. Transaction code like this,
db