1.0.3 • Published 6 years ago

@makebestgame/co-mysql v1.0.3

Weekly downloads
1
License
ISC
Repository
-
Last release
6 years ago

@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
1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago