https://github.com/davidemiceli/sql-lego
SQL Lego is a lightweight library for building and composing SQL string statements without using the standard order.
https://github.com/davidemiceli/sql-lego
nodejs rdbms sql sqlbuilder
Last synced: 3 months ago
JSON representation
SQL Lego is a lightweight library for building and composing SQL string statements without using the standard order.
- Host: GitHub
- URL: https://github.com/davidemiceli/sql-lego
- Owner: davidemiceli
- License: mit
- Created: 2017-12-09T08:45:25.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-12-09T14:37:42.000Z (over 7 years ago)
- Last Synced: 2025-02-11T14:49:35.856Z (5 months ago)
- Topics: nodejs, rdbms, sql, sqlbuilder
- Language: JavaScript
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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
```javascript
// 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):
```javascript
sqlb.query.offset = [30];
```