Git Product home page Git Product logo

node-rdbms-interface's Introduction

node-rdbms-interface

An interface library for Node JS that can be used to abstract RDBMS level SQL queries with promise based interface.

An Example Code 'app.js'

// Required Components
var DbInterface = require ('node-rdbms-interface');
var MySqlDriver = require('node-rdbms-interface/mysql/mysql-driver');
var config = {
  host: "127.0.0.1",
  user: "root",
  password: "root",
  database: "test"
};

// Instantiate
var Db = new DbInterface(new MySqlDriver(config));

// Select All Entries from a table 'campaign'
Db.selectAll('campaign')
  .then(function(dataAarray) {
    // Do something with data here
    console.log(dataArray);
  }).catch(function(err) {
    // Log error on console
    console.error(err);
  });

// Select an entry by id from 'campaign'
var id = 10;
Db.selectById('campaign', id)
  .then(function(dataObj) {
    // Do something with data here
    console.log(dataObj);
  }).catch(function(err) {
    // Log error on console
    console.error(err);
  });

// Build a Complex Query Using QueryBuilder
var selector = {
  "campaign.id": "id",
  "campaign.campaign_name": "campaign_name",
  "advertiser.name": "advertiser",
  "status.name": "status",
};

Db.build()
  .select(selector, true)
  .from('campaign')
  .join('advertiser', { "advertiser.id": "campaign.advertiser_id" })
  .join("status", { "status.id": "campaign.status" })
  .where({ "campaign.id": id })
  .compile()
  .exec()
  .then(function(dataArray) {
    // Do something with data here
    console.log(dataArray);
  })
  .catch(function(err) {
    // Log error on console
    console.error(err);
  });

**** DOCUMENTATION PENDING ****

node-rdbms-interface's People

Contributors

tusharsrivastava avatar

Stargazers

 avatar

Watchers

 avatar  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.