| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
KiteSQL is a lightweight embedded relational database for Rust, inspired by MyRocks and SQLite and fully written in Rust. It is designed to work not only as a SQL engine, but also as a Rust-native data API that can be embedded directly into applications without relying on external services or heavyweight infrastructure.
KiteSQL supports direct SQL execution, typed ORM models, schema migration, and builder-style queries, so you can combine relational power with an API surface that feels natural in Rust. On native targets, KiteSQL ships with both RocksDB-backed and LMDB-backed persistent storage builders, plus an in-memory builder for tests and temporary workloads.
KiteSQL includes a built-in ORM behind the orm feature flag. With #[derive(Model)], you can define typed models and get tuple mapping, schema creation, migration support, projections, set queries, and builder-style query/mutation workflows.
Model changes are part of the normal workflow. KiteSQL ORM can help evolve tables for common schema updates, including adding, dropping, renaming, and changing columns, so many migrations can stay close to the Rust model definition instead of being managed as hand-written SQL.
For the full ORM guide, see src/orm/README.md.
use kite_sql::db::DataBaseBuilder;
use kite_sql::errors::DatabaseError;
use kite_sql::orm::OrmQueryResultExt;
use kite_sql::Model;
#[derive(Default, Debug, PartialEq, Model)]
#[model(table = "users")]
#[model(index(name = "users_name_age_idx", columns = "name, age"))]
struct User {
#[model(primary_key)]
id: i32,
#[model(unique, varchar = 128)]
email: String,
#[model(rename = "user_name", varchar = 64)]
name: String,
#[model(default = "18", index)]
age: Option<i32>,
}
fn main() -> Result<(), DatabaseError> {
let mut database = DataBaseBuilder::path("./data").build_rocksdb()?;
// Or: let database = DataBaseBuilder::path("./data").build_lmdb()?;
database.migrate::<User>()?;
database.insert_many([
User {
id: 1,
email: "alice@example.com".to_string(),
name: "Alice".to_string(),
age: Some(18),
},
User {
id: 2,
email: "bob@example.com".to_string(),
name: "Bob".to_string(),
age: Some(24),
},
])?;
database
.bind(|ctx| {
ctx.mutate::<User>()?
.filter(|e| e.column(User::id())?.eq(1))?
.update(|u| u.set_value(User::age(), Some(19)))
})?
.done()?;
database
.bind(|ctx| {
ctx.mutate::<User>()?
.filter(|e| e.column(User::id())?.eq(2))?
.delete()
})?
.done()?;
let users = database
.bind(|ctx| {
ctx.from::<User>()?
.filter(|e| e.column(User::age())?.gte(18))?
.project_scalars((User::id(), User::name()))?
.order_by(User::name())?
.limit(10)?
.finish()
})?
.project_tuple::<(i32, String)>();
for user in users {
println!("{:?}", user?);
}
// For ad-hoc or more SQL-shaped workloads, `run(...)` is still available.
Ok(())
}On native targets, LMDB shines when reads dominate, while RocksDB is usually the stronger choice when writes do. Checkpoint support and feature-gating details are documented in docs/features.md.
👉more examples
import { WasmDatabase } from "./pkg/kite_sql.js";
const db = new WasmDatabase();
await db.ddl("create table demo(id int primary key, v int)");
await db.execute("insert into demo values (1, 2), (2, 4)");
const rows = db.run("select * from demo").rows();
console.log(rows.map((r) => r.values.map((v) => v.Int32 ?? v)));import kite_sql
db = kite_sql.Database.in_memory()
db.execute("create table demo(id int primary key, v int)")
db.execute("insert into demo values (1, 2), (2, 4)")
for row in db.run("select * from demo"):
print(row["values"])Run make tpcc (or cargo run -p tpcc --release) to execute the benchmark against the default KiteSQL storage. Use --backend rocksdb or --backend lmdb to compare the two persistent backends directly.
Run make tpcc-dual to mirror every TPCC statement to an in-memory SQLite database alongside KiteSQL and assert the two engines return identical results; this target runs for 60 seconds (--measure-time 60). Use cargo run -p tpcc --release -- --backend dual --measure-time <secs> for a custom duration.
Recent stable-run 720-second local comparison on the machine above:
| Backend | TpmC | New-Order p90 | Payment p90 | Order-Status p90 | Delivery p90 | Stock-Level p90 |
|---|---|---|---|---|---|---|
| KiteSQL LMDB | 82871 | 0.001s | 0.001s | 0.001s | 0.002s | 0.001s |
| KiteSQL RocksDB | 40960 | 0.001s | 0.001s | 0.001s | 0.011s | 0.001s |
| SQLite balanced | 51637 | 0.001s | 0.001s | 0.001s | 0.001s | 0.001s |
| SQLite practical | 61424 | 0.001s | 0.001s | 0.001s | 0.001s | 0.001s |
These rows are from the stable runs on 2026-07-11; the detailed raw outputs are recorded in tpcc/README.md.
KiteSQL uses the Apache 2.0 license to strike a balance between open contributions and allowing you to use the software however you want.
| Back | FazBrowse Home | New Git URL |