Socket
Socket
Sign inDemoInstall

sql-lego

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    sql-lego

SQL Lego is a lightweight library for building and composing SQL string statements without the standard order.


Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Install size
2.91 kB
Created
Weekly downloads
 

Readme

Source

sql-lego

SQL Lego is a lightweight library for building and composing SQL string statements without the standard order.

Installation

To install sql-lego with npm package manager

npm install sql-lego

Getting Started

// Requirements
const SQLego = require('sql-lego');

// Init sqlego instance
const sqlb = new SQLego();

// Compose query in unordered way
sqlb.query.limit = [0,10];
sqlb.query.from = [`users AS u`];
sqlb.query.where.push({
  operator: 'AND',
  condition: 'u.age >= 30'
},{
  operator: 'OR',
  condition: `p.tag = 'travel'`
});
sqlb.query.select = [
  'u.id AS user_id',
  `COUNT(*) AS num`
];
sqlb.query.orderby = ['num DESC'];
sqlb.query.joins = [
  `INNER JOIN posts AS p ON p.user_id=u.id`,
];
sqlb.query.groupby = ['u.id'];

sqlb.query.where.push({
  operator: 'OR',
  condition: `p.tag = 'food'`
});

// Return the sql string in the right order
const result = sqlb.toSQL();
console.log(result);

Notes

It supports also the OFFSET condition (for example, used by Apche Drill):

sqlb.query.offset = [30];

Keywords

FAQs

Last updated on 09 Dec 2017

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc