Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/gvanderest/seaql

SQL Building Library
https://github.com/gvanderest/seaql

generator mysql postgres sql

Last synced: 8 days ago
JSON representation

SQL Building Library

Awesome Lists containing this project

README

        

# SeaQL

Library for generating some SQL, primarily targeting MySQL and Postgres databases.

## Installation

```shell
yarn add seaql
```

## Examples

### Insert

```js
import { insert } from "seaql";

const sql = insert({ firstName: "Guillaume", lastName: "VanderEst" }).into("customers").stringify();

# INSERT INTO customers (firstName, lastName) VALUES ('Guillaume', 'VanderEst');
```

### Select

```js
import { select } from "seaql";

const sql = select(["id"]).from("customers").where({ firstName: "Guillaume", lastName: "VanderEst" }).stringify();

# SELECT id FROM customers WHERE firstName = 'Guillaume' AND lastName = 'VanderEst';
```

### Update

```js
import { update } from "seaql";

const sql = update("customers").set({ firstName: "Edward", lastName: "Nigma" }).where({ id: 12345 }).stringify();

# UPDATE customers SET firstName = 'Edward', lastName = 'Nigma' WHERE id = 12345;
```

### Delete

Alternatively, `del` can be used. As `delete` is a reserved JavaScript keyword.

```js
import { remove } from "seaql";

const sql = remove("customers").where({ id: 12345 }).stringify();

# DELETE customers WHERE id = 12345;
```

## Future
* Value escaping
* Validations for when some functions can be called
* Handling primitives vs arrays flexibly
* Table+Field combinations
* Field aliasing
* Joins
* Nested SeaQL subqueries
* Parsing from SQL
* Aggregate functions
* Nesting of OR and AND clauses using arrays/objects
* Limits
* Filtering
* Ordering
* Partitioning?
* Engine-specific optimizations
* Returning clauses
* Select with no fields provided performing *