@makebestgame/co-mysql
v1.0.3
Published
@makebestgame/co-mysql is a [mysql](https://github.com/mysqljs/mysql) wrapper to be used with [visionmedia's co](https://github.com/visionmedia/co) library which has a centralized config.
Downloads
8
Readme
@makebestgame/co-redis is a mysql wrapper to be used with visionmedia's co library.
Usage
const mysql_config = {
"test": {
"host": "localhost",
"port": 3306,
"user": "root",
"password": "",
"charset": "utf8",
"debug": false,
"notoolquery": true,
"database": "test"
},
};
const co = require('co');
const wrapper = require('./index');
wrapper.init(mysql_config);
const conn = wrapper.get('test');
co(async function () {
const insertSql = 'insert into tt set ?';
const col2 = 100;
const data = {
col1: 'this is col1',
col2,
};
let res = await conn.query(insertSql, data);
console.log('got', res); // logs 1
const searchSql = 'select col1 from tt where col2 = ?';
res = await conn.query(searchSql, [col2]);
console.log('got', res); // logs 1
const deleteSql = 'delete from tt where col2 = ?';
res = await conn.query(deleteSql, [col2]);
console.log('delete res', res);
return true;
}).then(
(data) => console.log('end ok', data),
err => console.log('end error', err),
);
Installation
$ npm install @makebestgame/co-mysql