New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

node-database-connectors

Package Overview
Dependencies
Maintainers
0
Versions
74
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.16
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
43
decreased by-18.87%
Maintainers
0
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 07 Jan 2025

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc