8 unstable releases (3 breaking)
Uses new Rust 2024
| new 1.0.0 |
|
|---|---|
| 0.4.3 | Mar 8, 2026 |
| 0.3.0 | Mar 6, 2026 |
| 0.2.0 | Mar 5, 2026 |
| 0.1.1 | Mar 2, 2026 |
#1106 in Database interfaces
43KB
929 lines
NahSQL
Disclaimer: NahSQL is in early stages of development and is not currently functional.
NahSQL is a simple and purpose-built database inspired by SQLite but differs in the way it is queried using a Rust API rather than SQL.
Examples
Synchronous, without tokio:
use nahsql::{database::Database, schema::SchemaBuilder, value::ValueType};
fn main() -> anyhow::Result<()> {
let schema = SchemaBuilder::new(|schema| {
Ok(schema.table("users", |table| {
Ok(table
.field("id", |field| Ok(field.r#type(ValueType::String).key()))?
.field("name", |field| Ok(field.r#type(ValueType::String).key()))?
.field("passphrase", |field| Ok(field.r#type(ValueType::String)))?
.primary_key("id"))
})?)
})?;
let db = Database::open_sync("./database", schema)?;
Ok(())
}
Asynchronous, with tokio:
use nahsql::{database::Database, schema::SchemaBuilder, value::ValueType};
#[tokio::main]
fn main() -> anyhow::Result<()> {
let schema = SchemaBuilder::new(|schema| {
Ok(schema.table("users", |table| {
Ok(table
.field("id", |field| Ok(field.r#type(ValueType::String).key()))?
.field("name", |field| Ok(field.r#type(ValueType::String).key()))?
.field("passphrase", |field| Ok(field.r#type(ValueType::String)))?
.primary_key("id"))
})?)
})?;
let db = Database::open_async("./database", schema).await?;
Ok(())
}
Dependencies
~1.7–3.5MB
~69K SLoC