1.7.15 • Published 5 months ago

node-database-connectors v1.7.15

Weekly downloads
44
License
Apache License 2....
Repository
github
Last release
5 months ago

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;
1.7.14

7 months ago

1.7.15

5 months ago

1.7.13

9 months ago

1.7.12

9 months ago

1.7.11

9 months ago

1.7.10

10 months ago

1.7.9

10 months ago

1.7.8

10 months ago

1.7.7

10 months ago

1.7.6

10 months ago

1.7.5

10 months ago

1.7.4

11 months ago

1.7.3

2 years ago

1.7.2

2 years ago

1.7.1

2 years ago

1.7.0

2 years ago

1.6.9

3 years ago

1.6.8

3 years ago

1.6.4

3 years ago

1.6.3

3 years ago

1.6.7

3 years ago

1.6.6

3 years ago

1.6.5

3 years ago

1.6.2

3 years ago

1.6.1

4 years ago

1.6.0

4 years ago

1.5.3

4 years ago

1.5.2

4 years ago

1.5.1

4 years ago

1.5.0

4 years ago

1.3.0

4 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.10

5 years ago

1.1.9

5 years ago

1.1.8

5 years ago

1.1.7

5 years ago

1.1.6

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.20

7 years ago

1.0.19

7 years ago

1.0.18

7 years ago

1.0.17

7 years ago

1.0.16

7 years ago

1.0.15

7 years ago

1.0.14

7 years ago

1.0.12

7 years ago

1.0.11

7 years ago

1.0.10

8 years ago

1.0.9

8 years ago

1.0.8

8 years ago

1.0.7

8 years ago

1.0.6

8 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

9 years ago

0.0.13

9 years ago

0.0.11

9 years ago

0.0.10

9 years ago

0.0.9

9 years ago

0.0.8

10 years ago

0.0.7

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago

0.0.0

10 years ago