A simple to use wrapper over Node.JS mysql library
I was working on a project on Node.JS platform. In this project I was suppose to exchange data with MySql server. For this purpose I used two packages which are available in NPM repository, namely, mysql and mysql-queues. Later is required because former driver yet doesn't support transaction feature of MySql database. If you go through them you will be confused a little bit and will find it difficult to understand in one go. To simplify this situation I created an easy to use wrapper over these two libraries.
You can find my wrapper on GitHub by following this link. I am still in progress of making it feature rich.
How to use this wrapper:
Now you can use it in a way that is specified below:
You can find my wrapper on GitHub by following this link. I am still in progress of making it feature rich.
How to use this wrapper:
- Install mysql and mysql-queues using npm install command.
- Download wrapper by going on this link.
Now you can use it in a way that is specified below:
Initialize object
var dbClass = require('DB'); var options = {}; options.host = 'localhost'; options.user = 'root'; options.password = 'root'; options.database = 'test'; var db = new dbClass.DB(options);
Select statement
db.sql = 'select * from test where id = ? and name=?'; db.bindParams([id,name]); db.select(function(err, results, fields){ .. .. });
Transaction statement
db.sql = 'insert into test (name) values (?)'; db.startTransaction(); db.insertTransaction(['bharat'],function(err, info) { if(err) { console.log('error'); console.log(err); db.rollback(); } else { id = info.insertId; db.commit(); } }); db.executeTransaction();
Comments
IEEE Final Year Projects for CSE
IEEE Project Centers in Chennai
android based projects
Java Training in Chennai
Project Center in Chennai
Java Training in Chennai
projects for cse
The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing,
and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training Project Centers in Chennai
Android Final Year Project Ideas for Computer Science. IEEE Android Projects for CSE 2020 - 2021 - WISEN
http://projectcentersinchennai.co.in
http://wisenitsolutions.com
Post a comment