# node-database-connectors

> connector to convert JSON to database specific query

Latest version **1.7.20** (published 2026-01-06) · Apache License 2.0 license · 0 weekly downloads

## Install

```sh
npm install node-database-connectors
pnpm add node-database-connectors
yarn add node-database-connectors
bun add node-database-connectors
```

## Health

**Score 45/100 (D)** — status: stable.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

## Facts

| | |
|---|---|
| Version | 1.7.20 |
| Published | 2026-01-06 |
| First published | 2015-01-08 |
| Weekly downloads | 0 |
| License | Apache License 2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 239.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Darshit Shah |
| Maintainers | darshit-shah |

## Links

- npm: https://www.npmjs.com/package/node-database-connectors
- Repository: https://github.com/darshit-shah/node-database-connectors
- Issues: https://github.com/darshit-shah/node-database-connectors/issues
- npm.io page: https://npm.io/package/node-database-connectors

## Dependencies (7)

- [pg](https://npm.io/package/pg.md) 8.7.3
- [mssql](https://npm.io/package/mssql.md) *
- [mysql2](https://npm.io/package/mysql2.md) *
- [snowflake-sdk](https://npm.io/package/snowflake-sdk.md) *
- [@apla/clickhouse](https://npm.io/package/@apla/clickhouse.md) *
- [cassandra-driver](https://npm.io/package/cassandra-driver.md) *
- [@google-cloud/bigquery](https://npm.io/package/@google-cloud/bigquery.md) *

## Recent versions

- 1.7.20 (latest) — 2026-01-06
- 1.7.18 — 2025-05-30
- 1.7.17 — 2025-05-03
- 1.7.16 — 2025-01-07
- 1.7.15 — 2024-07-19
- 1.7.14 — 2024-05-30
- 1.7.13 — 2024-03-29
- 1.7.12 — 2024-03-27
- 1.7.11 — 2024-03-22
- 1.7.10 — 2024-03-08
- 1.7.9 — 2024-02-23
- 1.7.8 — 2024-02-21
- 1.7.7 — 2024-02-20
- 1.7.6 — 2024-02-20
- 1.7.5 — 2024-02-12
- … 62 more at https://npm.io/package/node-database-connectors/versions

## README

[![CodeQL](https://github.com/darshit-shah/node-database-connectors/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/darshit-shah/node-database-connectors/actions/workflows/github-code-scanning/codeql)
[![Node.js Package](https://github.com/darshit-shah/node-database-connectors/actions/workflows/npm-publish.yml/badge.svg?event=release)](https://github.com/darshit-shah/node-database-connectors/actions/workflows/npm-publish.yml)

## NODE-DATABASE-CONNECTORS
#### Author: Axiom
##### Created on: 3rd Dec 2015


#### Function

* _prepareQuery :_

  ```javascript  
  var connectionIdentifier = require('node-database-connectors');  
  var objConnection = connectionIdentifier.identify(sampleConfig);
  var query = objConnection.prepareQuery(jsonQuery);
    ```



  - _sampleConfig_ : Configuration for database connection. (As given below)
  ```javascript
  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)_
  ```javascript
    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 :_  
    ``` javascript

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

    ```

  * _Sample 2 (Select Query)_
  ```javascript
  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 :_
  ``` javascript

    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)_
  ```javascript
  var jsonQuery = {
    table: "tbl_SampleMaster",
    insert: [{
      field: 'SM_code',
      fValue: 'D0001'
    }, {
      field: 'SM_fname',
      fValue: 'Digi'
    }, {
      field: 'SM_lname',
      fValue: 'Corp'
    }],
  };
  ```
  _Output :_
  ``` javascript

    INSERT INTO tbl_PersonMaster(`SM_code`,`SM_fname`,`SM_lname`)
    VALUES(`D001`,`Digi`,`Corp`);
    ```


  * _Sample 3-1 (Insert Query)_
  ```javascript
  var jsonQuery = {
    table: "tbl_PersonMaster",
    insert:{
      field:['PM_Code','PM_fname','PM_lname'],
      fValue:[['CorDig','Digi', 'Corp'],['SofMic','Micro', 'Soft']],
    }
  };
  ```
  _Output :_
  ``` javascript
    INSERT INTO tbl_PersonMaster(`PM_Code`,`PM_fname`,`PM_lname`)
    VALUES((`CorDig`,`Digi`,`Corp`),(`SofMic`,`Micro`,`Soft`))
    ```



  * _Sample 4 (Update Query)_
  ```javascript
  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 :_
  ``` javascript

    UPDATE tbl_PersonMaster SET ``.`SM_code`=`D001`,``.`PM_fname`=`Ashraf`,``.`PM_lname`=`Ansari`
    WHERE (``.`pk_id` = '1');
    ```

  * _Sample 5 (Delete Query)_
  ```javascript
  var jsonQuery = {
    table: "tbl_PersonMaster",
    alias: "PM",
    delete: [],
    filter: {
      AND: [{
        field: 'pk_id',
        operator: 'EQ',
        value: '1'
      }]
    }
  };
  ```
  _Output :_
  ``` javascript

    DELETE FROM tbl_PersonMaster WHERE(``.`pk_id` = '1');
    ```
  - _jsonQuery_ : JSON structure of Select with aggregation
  * _Sample 6 (Select Query)_
  ```javascript
    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 :_  
    ``` javascript

    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)_
  ```javascript
    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 :_  
    ``` javascript

    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;

    ```

---
_Source: https://npm.io/package/node-database-connectors · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
