SqliteBruv
A Simple and Efficient Query Builder for SQLite
Lightweight, modular, and secure SQLite query builder designed to simplify
database interactions and optimize performance. Key Features:
- Simple Query Building: Construct complex queries with ease.
- Parameterized Queries: Prevent SQL injection attacks.
- Works with cloudflare D1.
- Works with bun's Inbuilt SQLite.
- Provides raw query.
- Zero Deps
Installation
Install sqlitebruv with npm
npm install sqlitebruv
Usage/Examples
import { SQLiteBruv } from "SQLiteBruv";
const db = Database.open("database.db");
db.run(`
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
email TEXT NOT NULL,
age INTEGER,
country TEXT
);
`);
const queryBuilder = new SqliteBruv({
db,
D1: {
accountId: "xxx",
databaseId: "xxx",
apiKey: "xxx",
},
});
await queryBuilder
.from("users")
.insert({ name: "John Doe", email: "john@example.com" })
.then((changes) => {
});
await queryBuilder
.from("users")
.where("id = ?", 1)
.update({ name: "Jane Doe" })
.then((changes) => {
});
await queryBuilder
.from("users")
.where("id = ?", 1)
.andWhere("name LIKE ?", `%oh%`)
.get()
.then((changes) => {
});
await queryBuilder
.from("users")
.select("*")
.where("id = ?", 1)
.delete()
.then((changes) => {
console.log({ changes });
});
queryBuilder
.from("users")
.get()
.then((changes) => {
});
await queryBuilder
.from("users")
.where("id = ?", 1)
.getOne()
.then((changes) => {
});
await queryBuilder
.from("users")
.select("id", "name")
.get()
.then((changes) => {
});
await queryBuilder
.from("users")
.where("age > ?", 18)
.get()
.then((changes) => {
});
await queryBuilder
.from("users")
.where("age > ?", 18)
.andWhere("country = ?", "USA")
.get()
.then((changes) => {
});
await queryBuilder
.from("users")
.where("age > ?", 18)
.orWhere("country = ?", "Canada")
.get()
.then((changes) => {
});
await queryBuilder
.from("users")
.limit(10)
.offset(5)
.get()
.then((changes) => {
});
await queryBuilder
.from("users")
.orderBy("name", "ASC")
.get()
.then((changes) => {
});
await queryBuilder
.from("users")
.orderBy("name", "ASC")
.get()
.then((changes) => {
});
License
MIT
Contributing
Contributions are always welcome! creates issues and pull requests.
Support