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

https://github.com/bsahd/sql-builder

A simple tool for building safe and readable SQL Querys
https://github.com/bsahd/sql-builder

sql sql-query

Last synced: 8 months ago
JSON representation

A simple tool for building safe and readable SQL Querys

Awesome Lists containing this project

README

          

# A simple tool for building safe and readable SQL Querys

## Features

- Safe SQL building
- No additional dependencies

## Example

```js
import SQL from "@bsahd/sql-builder";
import { DatabaseSync } from "node:sqlite";
const dbsq = new DatabaseSync(":memory:");
const db = new SQL(
(q) => dbsq.exec(q),
(q) => dbsq.prepare(q),
);
db.run("CREATE TABLE users(name VARCHAR, age INTEGER)");
db.insert("users")
.values({ name: "john' doe", age: 25 })
.values({ name: "alice", age: 29 })
.values({ name: "bob", age: 31 })
.run();
console.log(db.select("users").run().all());
db.update("users")
.set("name", "charry")
.set("age", 26)
.where(SQL.and(SQL.eq("name", "alice"), SQL.eq("age", 29)))
.run();
console.log(db.select("users").run().all());
db.delete("users")
.where(SQL.and(SQL.eq("name", "john' doe"), SQL.eq("age", 25)))
.run();
console.log(db.select("users").run().all());
```