1.0.17 • Published 2 years ago

crcis-mssql-context v1.0.17

Weekly downloads
7
License
ISC
Repository
gitlab
Last release
2 years ago

About Project

Provide the main entry for connecting to MSSQL is the most project goal. This project is a wrapper for the MSSQL Node.js package. I use the config package for supporting multiple databases in the project.

Config sample

{
    "dbConfig": {
        "databaseName1": {
            "host": "DomainNameOrDomainIP",
            "port": 1433,
            "database": "YourDatabaeName",
            "userName": "YourDatabaseUserName",
            "password": "YourDatabasePassword"
        },
        "databaseName2": {
            "host": "DomainNameOrDomainIP",
            "port": 1433,
            "database": "YourDatabaeName",
            "userName": "YourDatabaseUserName",
            "password": "YourDatabasePassword"
        }
    },
}

Simple Code Sample

const context = require("crcis-mssql-context");

module.exports = async function () {
  await context
    .runCommand("databaseName", "SELECT @@VERSION AS [version]")
    .then((result) => {
      if (result !== null && result[0] !== null) console.log(result[0].version);
    })
    .catch((err) => console.log(err));
};

Using Table Valued Parameters (TVP)

const context = require("crcis-mssql-context");

module.exports.create = async (rows) => {
    let paramList = [];
    context.addInputParamToTVP("column1", "int", paramList);
    context.addInputParamToTVP("column2", "varchar", paramList);
    context.addInputParamToTVP("column3", "nvarchar", paramList);

    let tvp = context.createSqlTable(paramList);

    for (let i = 0; i < rows ; i++) {
      tvp.rows.add(
        parseInt(rows[i].value1),
        rows[i].value2,
        rows[i].value3       
      );
    }

    await context
      .runStoredProcedure("databaseName","spName", null, "tvpName",tvp)
      .then((data) => {
        
      })
      .catch((err) => {
        console.log(err);
      });
}
1.0.17

2 years ago

1.0.16

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.9

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago