Latest Socket ResearchMalicious Chrome Extension Performs Hidden Affiliate Hijacking.Details
Socket
Book a DemoInstallSign in
Socket

es6-sql

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

es6-sql

Write SQL with SQL

npmnpm
Version
0.0.0
Version published
Maintainers
1
Created
Source

es6-sql

warning: in development, do not use, but do contribute 😺

Stop wasting your life with embedded DSLs [1], and just write SQL.

sql`SQL...`

Interpolate scope safely into SQL statement.

var sql = require('es6-sql');

var table = 'interp_user_table',
    user_id = 100;

var query = sql`
    SELECT *
    FROM ${table}
    WHERE
        user_id = ${user_id}
        OR user_id IN (1,2,3)
        OR user_id IN (${sql`SELECT user_id FROM all_users WHERE is_active = True`})`
    .and`hello = ${123}`
    .or`foo IN (SELECT foo FROM foo)`;

sql.and`SQL...`

sql.or`SQL...`

Compose your SQL filters using AND.

sql.toString()

Serialize your SQL statement into a string with values interpolated.

console.log(query.toString());
SELECT *
  FROM `interp_user_table`
  WHERE (((((`user_id` = `$1`) OR (`user_id` IN (1, 2, 3))) OR (`user_id` IN (`SELECT `user_id`
    FROM `all_users`
    WHERE (`is_active` = TRUE)`))) AND (`hello` = `$2`)) OR (`foo` IN (
    SELECT `foo`
      FROM `foo`
  )))

sql.parameters

console.log(query.parameters);
[100, 123]

[1]

Keywords

sql

FAQs

Package last updated on 29 Sep 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