🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

node-database-connectors

Package Overview
Dependencies
Maintainers
1
Versions
76
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-database-connectors

connector to convert JSON to database specific query

1.7.14
Source
npm
Version published
Weekly downloads
102
363.64%
Maintainers
1
Weekly downloads
 
Created
Source

CodeQL Node.js Package

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;
    
    

FAQs

Package last updated on 30 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts