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
- Host: GitHub
- URL: https://github.com/bsahd/sql-builder
- Owner: bsahd
- License: mit
- Created: 2025-05-09T09:10:47.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-07-18T04:10:56.000Z (11 months ago)
- Last Synced: 2025-07-18T08:02:04.693Z (11 months ago)
- Topics: sql, sql-query
- Language: JavaScript
- Homepage:
- Size: 40 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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());
```