项目作者: eternalsayed

项目描述 :
DB Helper for NodeJS projects
高级语言: JavaScript
项目地址: git://github.com/eternalsayed/es-helper-mysql.git
创建时间: 2019-03-02T08:57:11Z
项目社区:https://github.com/eternalsayed/es-helper-mysql

开源协议:

下载


es-helper-mysql

Utility functions wrapper over native NodeJS mysql package to perform operations like connect, querying, insertion, batch-insertion, etc. easily. Could be buggy; use at your risk. Has bee helping me though in a number of projects over years.

Installation

You can install the utility using npm, or you can simply download the zip (Click on ‘Download zip’ button above) and reference the index.js file in your NodeJS code. Please note that this code is not to be used in Front End as not only it is irrelevant, but may fail as well.

Using npm, run below command:

npm i --save https://github.com/eternalsayed/es-helper-mysql

Usage

  1. const esMysql = require('es-helper-mysql');
  2. const dbo = esMysql.getDbHandle();
  3. const instance = dbo.getInstance();
  4. instance.query('SELECT * FROM users', (err, res) => {
  5. instance.end();//don't keep the resources occupied!
  6. callback(err, res);
  7. });

Helper functions

connect()

Selects one of the configuration from availables ones, based on the __mode set via setCommonGlobals in es-util-app. Since you can override these values (not advisable though) at any place, you can choose any of the configurations of available DB configs before the connect function is called.

Contributing:

You’re more than welcome to help me improvise this code. To begin, fork the project, create a branch in your name from master and when you’re done, please raise a pull-request. I’ll try to be prompt in merging your requests ASAP.