https://github.com/murphsicles/zsql
@db/zsql — Lightweight embedded SQL database for Zeta
https://github.com/murphsicles/zsql
Last synced: 22 days ago
JSON representation
@db/zsql — Lightweight embedded SQL database for Zeta
- Host: GitHub
- URL: https://github.com/murphsicles/zsql
- Owner: murphsicles
- License: mit
- Created: 2026-05-29T05:39:36.000Z (2 months ago)
- Default Branch: main
- Last Pushed: 2026-05-29T05:39:39.000Z (2 months ago)
- Last Synced: 2026-05-29T07:27:48.196Z (2 months ago)
- Size: 104 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ZSQL
[](https://zeta-lang.org)
[](https://zorbs.io/@db/zsql)
[](https://github.com/murphsicles/zsql)
Lightweight embedded SQL database for Zeta. ZSQL wraps SQLite3 — giving you a zero-config, serverless SQL engine backed by the most widely deployed database engine in the world.
ZSQL is a companion to [Zenith](https://zorbs.io/@db/zenith) — use Zenith for fast in-memory key-value workloads and ZSQL for persistent SQL querying.
## Quick Start
Add to your `zorb.toml`:
```toml
[dependencies]
@db/zsql = "1.0"
```
Open a database and execute queries:
```zeta
use @db/zsql::Connection;
fn main() {
let conn = Connection::open("my_data.db").unwrap();
conn.execute("CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
age INTEGER
)", []).unwrap();
conn.execute("INSERT INTO users (name, age) VALUES (?1, ?2)",
params_from_iter(["Alice".into(), "30".into()])).unwrap();
let mut stmt = conn.prepare("SELECT id, name, age FROM users WHERE age > ?1").unwrap();
let rows = stmt.query_map([25], |row| {
(row.get::(0).unwrap(), row.get::(1).unwrap(), row.get::(2).unwrap())
}).unwrap();
for row in rows {
let (id, name, age) = row.unwrap();
print("User {}: {} (age {})\n", id, name, age);
}
}
```
## In-Memory Database
```zeta
let conn = Connection::open_in_memory().unwrap();
conn.execute_batch("CREATE TABLE t (x INTEGER); INSERT INTO t VALUES (1), (2), (3);").unwrap();
```
## Transactions
```zeta
let tx = conn.transaction_with_behavior(TransactionBehavior::Immediate, true).unwrap();
tx.execute("UPDATE accounts SET balance = balance - 100 WHERE id = 1", []).unwrap();
tx.commit().unwrap();
```
## API
| Function / Type | Description |
|----------------|-------------|
| `Connection::open(path)` | Open or create a SQLite database file |
| `Connection::open_in_memory()` | Create an in-memory database |
| `conn.execute(sql, params)` | Execute a query |
| `conn.prepare(sql)` | Prepare a statement |
| `stmt.query_map(params, f)` | Execute and map rows |
| `conn.transaction()` | Begin a transaction |
| `Transaction::commit()` / `.rollback()` | Commit or roll back |
## License
MIT