aa-mysql

A simple and flexible mysql library for node.

Stats

stars 🌟issues ⚠️updated 🛠created 🐣size 🏋️‍♀️
101Apr 29, 2017Apr 7, 2014Minified + gzip package size for aa-mysql in KB

Readme

aa-mysql Logo
A simple and flexible MySql library for node.

NPM Version  Node.js Version


Installation

$ npm install aa-mysql

Usage

// insert amoa400
conn.table('user').insert({name: 'amoa400'});

// find amoa400
conn.table('user').where({name: 'amoa400'}).find();

// rename amoa400 to cai0715
conn.table('user').where({name: 'amoa400'}).update({name: 'cai0715'});

// delete cai0715
conn.table('user').where({name: 'cai0715'}).delete();

// select users whose id is less than 2 or greater than 3, limit 10
conn.table('user').where({id: [2, '<']}, {id: [3, '>']}, 'OR').limit(10).select();

Example

var aamysql = require('aa-mysql');

// config
aamysql.config({
  host: 'localhost',
  port: 3306,
  user: 'root',
  pass: '',
  prefix: 'aa_',
  db: 'aa-mysql',
  connLimit: 20
});

// use single connection to query
// you can also use connection pool, and it is recommended
var conn = aamysql.create();
conn.connect(function(err) {
  if (err) {
    console.log(err);
    return;
  }

  // select
  conn.table('user').select(function(err, res) {
    if (err) {
      console.log(err);
      return;
    }
    console.log(res);
  });
  
  // transaction
  conn.transaction([
    conn.table('user').option({get: true}).insert({name: 'amoa400'}),
    conn.table('user').option({get: true}).insert({id: 'hi', name: 'cai0715'})
    // will cause rollback, because id must be number
  ], function(err, res) {
    if (err) {
      console.log(err);
      return;
    }
    console.log(res);
  });
});

Dependency

Docs

Users

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.