npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rest-mssql-nodejs

v1.0.10

Published

Makes a wrap of mssql package and allows rest mssql queries and stored procedures easier and faster

Downloads

186

Readme

rest-mssql-nodejs

The purpose of this library is behave as wrap of the mssql package with only two methods to simplify it.

Features!

  • Create an instance of MS SQL
  • Execute queries with/without parameters and get the data
  • Get all parameters of a procedure with each data type only for fill
  • Execute stored procedures with/without parameters and get the data
  • Allow retrieve one or multiple result sets

Installation

$ cd your_project
$ npm install --save rest-mssql-nodejs

Accepted data types

  • tinyint
  • smallint
  • int
  • bigint
  • decimal
  • numeric
  • float
  • money
  • smallmoney
  • datetime
  • date
  • time
  • varchar
  • char
  • text
  • nchar
  • nvarchar
  • ntext
  • blob
  • bit

Methods

| executeQuery (queryString, paramsData) | | | |----------------------------------------------|-----------------------------------------------------------------------|--------------------------------------------------------------| | Parameter1: queryString | Query is going to be executed | Example without parameter: select * from your_table;...; Example with parameter: select * from your_table where id = @id | | Parameter2: paramsData (optional) | Array of objects with the property: value is going to fill the params | Example: [{ name: 'id', type: 'Int', value: 1 }] |

| executeStoredProcedure (storedProcedure, schema, paramsData) | | | |--------------------------------------------------------------------|-------------------------------------------------------------------------|--------------------------| | Parameter1: storedProcedure | The stored procedure name you want to execute | | | Parameter2: schema (optional) | If you are using a different schema, specify it here | | | Parameter3: paramsData (optional) | Object with the property: value as your stored procedure is waiting for | Example: { id: 1 } |

Usage

/**
instance the class and pass the database config to the constructor 
you can declare this constant in the main file of your project and export it to use it in other files
**/
// filename: index.js
const rest = new (require('rest-mssql-nodejs'))({
    user: 'db_username',
    password: 'db_password',
    server: 'localhost', // replace this with your IP Server
    database: 'db_name',
    port: 1433, // this is optional, by default takes the port 1433
    options: { 
        encrypt: true // this is optional, by default is false
    } 
});

module.exports = {
    rest
}

// filename: controller.js
const { rest } = require('../../index.js');

// how to execute a query without parameters
const result = await rest.executeQuery(
    'select * from your_table'
);

// how to execute a query with parameters
const result = await rest.executeQuery(
`
    select 
        *
    from your_table 
    where (
        @id = 0 or id_id = @id
    )
    `,
    [{
        name: 'id',
        type: 'Int',
        value: 1
    }]
);

// print the result
console.log("QUERY RESULT: ", result.data);
//----------

// how to execute a stored procedure without parameters
const result = await rest.executeStoredProcedure('spName');

// how to execute a stored procedure with parameters
const result = await rest.executeStoredProcedure('spName', null, {
    id: 1
});

//print the result
console.log("STORED PROCEDURE RESULT: ", result.data);

License

MIT