@aux4/db-mssql

1.0.1 • Public • Published

@aux4/db-mssql

JavaScript

Install

$ npm install @aux4/db-mssql

Execute Query

const Database = require("@aux4/db-mssql");
const db = new Database({
  host: "localhost",
  user: "sa",
  password: "******",
  database: "master"
});

(async () => {
  await db.open();
  const { data } = await db.execute("select * from table where id = @id", { id: 1 });
  console.log(JSON.stringify(data, null, 2));
  await db.close();
})();

Query Stream

const Database = require("@aux4/db-mssql");
const db = new Database({
  host: "localhost",
  user: "sa",
  password: "******",
  database: "master"
});

const stream = await db.stream("select * from table where id = @id", { id: 1 });

stream.on("data", row => {
console.log(JSON.stringify(row, null, 2));
});

stream.on("error", err => {
console.error(err.message);
});

stream.on("close", async () => {
await db.close();
});

Command Line

Install

$ npm install --global @aux4/db
$ npm install --global @aux4/db-mssql

Usage

Execute Query

$ db execute --host localhost --port 1434 --user sa --database master --query "select * from table where id = @id" --id 1

Stream Query

$ db stream --host localhost --port 1434 --user sa --database master --query "select * from table where id = @id" --id 1

Using @aux4/config

create config.yaml

config:
  dev:
    mssql:
      host: localhost
      port: 1434
      user: sa
      password: "******"
      database: master
$ db execute --configFile config.yaml --config dev/mssql --query "select * from table where id = @id" --id 1

See Also

Readme

Keywords

Package Sidebar

Install

npm i @aux4/db-mssql

Weekly Downloads

0

Version

1.0.1

License

Apache-2.0

Unpacked Size

15.2 kB

Total Files

4

Last publish

Collaborators

  • aux4-dev