Skip to content

zhaoda/co-mysql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

look first

'use strict';

var mysql = require('mysql'),
  co = require('co'),
  thunkify = require('thunkify');

var pool = mysql.createPool({
  user: 'root'
});

var query = function(sql, values, cb) {
  if (typeof values === 'function') {
    cb = values;
    values = null;
  }
  pool.query(sql, values, function(err, rows) {
    cb(err, rows);
  });
};

query = thunkify(query);

co(function * () {
  var rows = yield query('select 1 AS q');
  console.log(rows);
})();

yes, you should not use co-mysql! >_<

NPM

node-mysql wrapper for co or koa

install

npm install co-mysql

how to use

var co = require('co'),
  mysql = require('co-mysql');

co(function*() {
  var connection = mysql.createConnection(options);
  connection.connect();
  var result = yield connection.query('SELECT 10086 + 10000 AS q');
  connection.end();
})();

use pool

var co = require('co'),
  mysql = require('co-mysql');

co(function*() {
  var pool = mysql.createPool(options);
  var result = yield pool.query('SELECT 1');
  pool.end();
})();

License

MIT

About

node-mysql wrapper for co

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published