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

querysql

v1.0.0

Published

node wrapper to call db stored proc based on user input and validate

Downloads

1

Readme

querysql

A node wrapper to run any Sql Server stored procedure driven by parameter.json.

REQUIRE

Parameter.json : parameter.son define the data structure of your sql server stored procedure. It is divided into three sections defined below:

  • Input: All the input fields required by the stored procedure
    • fieldname: name of the table field required input parameter example: providerCode

    • datatype: datatype for field value example: VarChar, int etc

    • required: (true/false) required field input parameter to not

        {
        	"input": [{
        		"fieldname" : "providerCode", 
        		"datatype": "VarChar",
        		"required": true
        		},
        		{
        		"fieldname" : "providerType", 
        		"datatype": "VarChar",
        		"required": false
        	}],
        	"output": [{
        		"fieldname" : "errorMsg", 
        		"datatype": "VarChar",
        		"length": 1000,
        		"required": true
        		}],
        	"storedProcedure": "app.proc_getProviderByCode"
        }

USAGE:

It would be better to define your data structure in a JSON file to keep things simple, clean and easy to edit. You can then either read from the file and pass to the module. This file (defined above) is very important for the module to run as it tells the module how your table structure looks like and how to perform validation.

After this all you need to do is pass the database configuration with this JSON file in it. First initialise the class with the config and then call the execute method with the input values.

NOTE: It is very important that the input value key matches the fieldname in the JSON file.

var fs = require('fs');
var dataStructure = fs.readFileSync(__dirname + '/../parameters.json', 'UTF-8');

// Constructing DB config object to initalize connection
var dbconfig = {
	user: 'admin',
	password: 'admin@123',
	host: '127.0.0.1',
	port: 1433,
	db: 'test',
	instance: 'test',
	sqlParams: dataStructure
};
var provider = new proc(dbconfig);

// execute the method now
provider.execute(params)
.then(function(data) {
	console.log(data);
})
.catch(function(error) {
	console.log(error);
}); 

ARGUMENTS

  • dbconfig : database configuration

    • user: database username
    • password: database password
    • host: database hostname
    • port: database port
    • db: database name
    • instance: database instance
    • sqlParams: sql data structure
  • params : input parameter object

TESTS

Both unit and integration tests are supported and you can either run all or a subset of tests.

# run all tests (unit and integration)
$ npm run test
# or
$ mocha test

# run all unit tests
$ mocha test/unit

# run a subset of unit tests
$ npm run unit-grep grep=test-case

# run all integration tests
$ npm run integration

# run mocha with coverage
$ npm run cover

DOCUMENTATION

You can rebuild this documentation by running the below which extracts all JSDoc annotations for .js files found within lib.

$ npm run docs

TODO

  • More Validation required