Code Monkey home page Code Monkey logo

node-database-connectors's Introduction

NODE-DATABASE-CONNECTORS

Author: Axiom

Created on: 3rd Dec 2015

Function

  • prepareQuery :

    var connectionIdentifier = require('node-database-connectors');  
    var objConnection = connectionIdentifier.identify(sampleConfig);
    var query = objConnection.prepareQuery(jsonQuery);
    • sampleConfig : Configuration for database connection. (As given below)
    var sampleConfig = {
      type: "database",
      engine: 'MyISAM',
      databaseType: 'mysql',
      database: 'database',
      host: "hostname",
      port: "port",
      user: "user",
      password: "password",
      cacheResponse: false
    };
    • jsonQuery : JSON structure of Select, Insert, Update, Delete for Generating query
    • Sample 1 (Select Query)
      var jsonQuery = {
        table: "tbl_SampleMaster",
        alias: "SM",
        select: [{
          field: 'pk_tableID',
          alias: 'pk'
        }, {
          field: 'refNumber'
        }],
        sortby: [{
          field: 'refNumber'
        }],
        filter: {
          AND: [{
            field: 'pk_id',
            operator: 'EQ',
            value: '1'
          }]
        }
      };

    Output :

    SELECT ``.`pk_tableID` as `pk`,``.`refNumber`
    FROM `tbl_SampleMaster` as TM
    WHERE (``.`pk_id` = '1')
    ORDER BY `refNumber` ASC;
    • Sample 2 (Select Query)
    var jsonQuery = {
      join: {
        table: 'tbl_tableMaster',
        alias: 'A',
        joinwith: [{
          table: 'tbl_OtherMaster',
          alias: 'B',
          joincondition: {
            table: 'A',
            field: 'TM_pk_id',
            operator: 'eq',
            value: {
              table: 'B',
              field: 'OT_fk_id'
            }
          }
        }]
      },
      select: [{
        table: 'A',
        field: 'pk_tableID',
        alias: 'pk'
      }, {
        table: 'B',
        field: 'refNumber'
      }],
      filter: {
        AND: [{
          field: 'pk_id',
          operator: 'EQ',
          value: '1'
        }]
      }
    };

    Output :

      SELECT `A`.`pk_tableID` as `pk`,`B`.`refNumber`
      FROM `tbl_tableMaster` as A
      INNER JOIN `tbl_OtherMaster` as B ON `A`.`TM_pk_id` = `B`.`OT_fk_id`
      WHERE (``.`pk_id` = '1');
    • Sample 3 (Insert Query)
    var jsonQuery = {
      table: "tbl_SampleMaster",
      insert: [{
        field: 'SM_code',
        fValue: 'D0001'
      }, {
        field: 'SM_fname',
        fValue: 'Digi'
      }, {
        field: 'SM_lname',
        fValue: 'Corp'
      }],
    };

    Output :

      INSERT INTO tbl_PersonMaster(`SM_code`,`SM_fname`,`SM_lname`)
      VALUES(`D001`,`Digi`,`Corp`);
    • Sample 3-1 (Insert Query)
    var jsonQuery = {
      table: "tbl_PersonMaster",
      insert:{
        field:['PM_Code','PM_fname','PM_lname'],
        fValue:[['CorDig','Digi', 'Corp'],['SofMic','Micro', 'Soft']],
      }
    };

    Output :

      INSERT INTO tbl_PersonMaster(`PM_Code`,`PM_fname`,`PM_lname`)
      VALUES((`CorDig`,`Digi`,`Corp`),(`SofMic`,`Micro`,`Soft`))
    • Sample 4 (Update Query)
    var jsonQuery = {
      table: "tbl_SampleMaster",
      update: [{
        field: 'SM_code',
        fValue: 'D001'
      }, {
        field: 'SM_fname',
        fValue: 'Digi'
      }, {
        field: 'SM_lname',
        fValue: 'Corp'
      }],
      filter: {
        AND: [{
          field: 'pk_id',
          operator: 'EQ',
          value: '1'
        }]
      }
    };

    Output :

      UPDATE tbl_PersonMaster SET ``.`SM_code`=`D001`,``.`PM_fname`=`Ashraf`,``.`PM_lname`=`Ansari`
      WHERE (``.`pk_id` = '1');
    • Sample 5 (Delete Query)
    var jsonQuery = {
      table: "tbl_PersonMaster",
      alias: "PM",
      delete: [],
      filter: {
        AND: [{
          field: 'pk_id',
          operator: 'EQ',
          value: '1'
        }]
      }
    };

    Output :

      DELETE FROM tbl_PersonMaster WHERE(``.`pk_id` = '1');
    • jsonQuery : JSON structure of Select with aggregation
    • Sample 6 (Select Query)
      var jsonQuery = {
        table: "tbl_SampleMaster",
        alias: "SM",
        select: [{
          field: 'pk_tableID',
          alias: 'pk'
        }, {
          field: 'refNumber',
          aggregation:"count"
        }],
        sortby: [{
          field: 'refNumber'
        }],
        filter: {
          AND: [{
            field: 'pk_id',
            operator: 'EQ',
            value: '1'
          }]
        },
        groupby:[
         table: "SM",
         field: 'refNumber',
        ]
      };

    Output :

    SELECT ``.`pk_tableID` as `pk`,count(``.`refNumber`)
    FROM `tbl_SampleMaster` as TM
    WHERE (``.`pk_id` = '1')
    GROUP BY `refNumber`
    ORDER BY `refNumber` ASC;
    • jsonQuery : JSON structure of Select with nested aggregation
    • Sample 7 (Select Query)
      var jsonQuery = {
        table: "tbl_SampleMaster",
        alias: "SM",
        select: [{
          field: 'pk_tableID',
          alias: 'pk'
        }, {
          field: 'refNumber',
          aggregation:"count"
        }, {
          field: 'applicationCount',
          aggregation:["count","distinct"]
        }],
        sortby: [{
          field: 'refNumber'
        }],
        filter: {
          AND: [{
            field: 'pk_id',
            operator: 'EQ',
            value: '1'
          }]
        },
        groupby:[
         table: "SM",
         field: 'refNumber',
        ]
      };

    Output :

    SELECT ``.`pk_tableID` as `pk`,count(``.`refNumber`),count(distinct(``.`applicationCount`))
    FROM `tbl_SampleMaster` as TM
    WHERE (``.`pk_id` = '1')
    GROUP BY `refNumber`
    ORDER BY `refNumber` ASC;

node-database-connectors's People

Contributors

anokhimg avatar ashishvaghasiya avatar avinash110 avatar bvipul avatar chandrakant1990 avatar chandrakantthakkar avatar darshit-shah avatar dhavalbyteprophecy avatar jaymovaliya avatar kushkhanapara avatar pratikborsadiya avatar saraogiraj94 avatar shahshailaja avatar shailee-byteprophecy avatar vrajbyte01 avatar vyasparth 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.