New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

sqlbind

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

sqlbind

Simple SQL parameterize query generator

unpublished
Source
npmnpm
Version
0.0.8
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Introduce

A simple SQL parameterized query generator for most SQL language

Install

npm install sqlbind.js

Basic Using

const {sql_bind, sql_val} = require(sqlbind);

const tb_name = "post";
const title = "hello";
const body = "hello world";

const sql = sql_bind`insert into ${tb_name}(title, body) values(${sql_val(title)}, ${sql_val(body)})`
console.log(sql)
/* output
{
  str: sql_bind`insert into post(title, body) values(?, ?);`,
  bindings: ["hello", "hello world"],
  ...
}
*/

// then you can use it with other database libary
const knex = requrie("knex")({client: 'pg'});
knex.raw(sql.str, sql.bindings)


// other dialect
console.log(sql.pg)
/* output
{
  str: sql_bind`insert into post(title, body) values($0, $1);`,
  bindings: ["hello", "hello world"]
}
*/

console.log(sql.mysql)
/* output
{
  str: sql_bind`insert into post(title, body) values(?c0, ?c1);`,
  bindings: {
    "c0": "hello",
    "c1": "hello world"
  }
}

console.log(sql.mssql)
/* output
{
  str: sql_bind`insert into post(title, body) values(@c0, @c1);`,
  bindings: {
    "c0": "hello",
    "c1": "hello world"
  }
}

console.log(sql.sqlite)
/* output
{
  str: sql_bind`insert into post(title, body) values($c0, $c1);`,
  bindings: {
    "c0": "hello",
    "c1": "hello world"
  }
}

*/

API

function sql_bind(expressions: any[])=>SqlBind
sql_bind`string text ${expression} string text`=>SqlBind

alias sb, generate sql statement with parameters

function sql_value(value: any)=\>SqlValue

alias sv, stored the value that will parameterized

function is_sql(arg: any)=>boolean

true if it is SqlBind or SqlBind

TODO

[ ] add custom validate
[ ] support more dialect

FAQs

Package last updated on 29 Nov 2018

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