Git Product home page Git Product logo

mysql-query's Introduction

MysqlQuery

Install

npm install benpptung/mysql-query -S

Instroduction

This is a mysql module wrapper with some methods to simplify sql query.

option

config to create mysql pool.

  • driver: mysql or mysql2 to choose among the two modules.

var db = new MysqlQuery(opt)

properties

  • mysql : mysql or mysql2, depends on the option.driver

  • pool : the pool created by mysql. This is a singleton object, that said, if multiple MysqlQuery instances created, all of them will share the same pool.

methods

this.query(method, sql, values, cb)

automatically release connection, and if any warning, it will query the warnings, and callback error with the warnings.

this.insertId(method, sql, values, cb)

Same as this.query(), but it will return the res.insertId if insertId exists.

this.objectSelect(method, sql, values, cb)

Same as this.query(), but it will return the res[0] as an object if exists.

this.arraySelect(method, sql, values, cb)

Same as this.query(), but it will treat res as an array, and return this array.

Example

inherits this object in the db api developement

const inherits = require('util').inherits;
const MysqlQuery = require('mysql-query');
const _proto = require('prototype');

inherits(User, MysqlQuery);
module.exports = User;
var prototype = Object.assign(User.prototype, _proto);


function User(opt) {
	MysqlQuery.call(this, opt);
}

/**
 * @public
 * @param {number}   uId
 * @param {function} cb
 */
prototype.find = function(uId, cb) {
  var sql = 'select * from User where uId = ?';
  this.objectSelect('find()', sql, [uId], cb);
}

mysql-query's People

Contributors

benpptung avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.