Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

any-db-params

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

any-db-params

Collect parameters and generate SQL placeholders for any database

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4
Maintainers
1
Weekly downloads
 
Created
Source

any-db-params

Collect parameters and create placeholders for SQL queries for any database supported by any-db.

Synopsis

createParams = require('any-db-params');

// Fake a queryable object (connection/transaction/pool etc)
var queryable = {
  adapter: { name: 'mssql' }
  query: function (sql, params) {
    console.log(sql, params);
  }
};

var param = createParams(queryable);
var sql = 'select * from people ' +
  'where age > ' + param('age', 30) +
  ' and weight > ' + param('weight', 70);

queryable.query(sql, param.values());

//=> 'select * from people where age > @age and weight > @weight' { age: 30, weight: 70 }

API

module.exports =: (Queryable) => ParamAccessor

ParamAccessor = ( (name: String, value?: Any) => String ) & {
  values: () => Object|Array
}

Given a Queryable, returns a ParamAccessor. A ParamAccessor is a function that accepts 1 or 2 arguments. With 2 arguments it sets a named parameter value and returns a placeholder, with 1 argument it returns the placeholder for a previously defined parameter.

A ParamAccessor also has a values method, which will return a shallow copy of it's internal value storage, suitable for passing as the second parameter to queryable.query.

License

MIT

Keywords

FAQs

Package last updated on 10 Jan 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc