Expand description
§nusadb — native Rust driver + ORM for NusaDB
nusadb speaks the Nusa Wire Protocol (PROTOCOL_VERSION 1.1)
directly over TCP — no engine linkage, no C bindings, no async runtime. It is built for three
things: fast (buffered framing, native value decoding, pooled connections), stable
(no panics in the library path, bounds-checked decoding, constant-time SCRAM verification), and
complete — because a driver is a SQL-text transport, it supports every query the server
accepts: any DDL/DML/SELECT, joins, CTEs, window functions, subqueries, set-ops, transactions,
stored procedures, and all 16 value types are decoded to native Rust.
§Quick start
use nusadb::{Connection, Value};
let mut conn = Connection::connect("nusadb://nusa-root@127.0.0.1:5678/nusadb")?;
conn.execute("CREATE TABLE t (id INT NOT NULL, name TEXT, PRIMARY KEY (id))")?;
conn.query_params("INSERT INTO t VALUES ($1, $2)", &[&1_i64, &"alice"])?;
let result = conn.query("SELECT id, name FROM t ORDER BY id")?;
for row in &result.rows {
let id: i64 = row.get(0)?;
let name: String = row.get(1)?;
println!("{id} {name}");
}§Transactions, pooling, ORM
use nusadb::{Pool, Config};
use nusadb::orm::{Select, Insert};
let pool = Pool::new(Config::from_url("nusadb://nusa-root@127.0.0.1:5678/nusadb")?, 8)?;
let mut conn = pool.get()?;
conn.transaction(|tx| {
Insert::into("t").set("id", 2_i64).set("name", "bob").run(tx)?;
Ok(())
})?;
let rows = Select::from("t").filter("id", 2_i64).limit(1).fetch(&mut conn)?;Re-exports§
pub use orm::Delete;pub use orm::FromRow;pub use orm::Insert;pub use orm::Select;pub use orm::Update;
Modules§
- orm
- Query-builder ORM (
Select/Insert/Update/Delete,orm::FromRow). A lightweight, native query-builder ORM overConnection. It emits NusaDB’s own SQL (double-quoted identifiers,$nparameters, constantLIMIT/OFFSET,RETURNING *) and decodes rows into user types viaFromRow.Selectcovers the SELECT surface: projection (columns/select_raw/distinct), joins (inner_join/left_join/right_join/full_join/cross_join), predicates (filter/gt/gte/lt/lte/ne/like/ilike/between/is_null/is_not_null/where_in/where_not_in/where_raw),group_by+having,order_by,limit/offset, set operations (union/union_all/intersect/except), and aggregate terminals (count/sum/avg/min/max). It is a thin convenience layer — drop to raw SQL any time withConnection::query/Connection::query_params.
Structs§
- Cancel
Handle - A connection’s cancellation key, usable from another connection to abort an in-flight statement.
- Config
- How to reach and authenticate to a server.
- Connection
- A synchronous connection to a NusaDB server.
- Notification
- A live connection to a NusaDB server.
An asynchronous
LISTEN/NOTIFYnotification delivered by the server (§ pub/sub). Collected by the connection while it is idle and returned fromConnection::notifications/Connection::poll_notification. - Pool
- A pool of NusaDB connections sharing one
Config. - Pooled
Connection - A connection checked out of a
Pool. Derefs toConnection; returns to the pool on drop unlessPooledConnection::discardwas called. - Prepared
- A prepared statement: a name the server holds a parsed plan under, reusable across executions.
- Query
Result - The outcome of a query: column metadata, the rows, and the server’s completion tag.
- Row
- One result row: its column values, plus a shared handle to the column names for by-name access.
- TlsConfig
- How to verify the server’s certificate.
Enums§
- Error
- A
nusadbdriver error. - TypeTag
- A column’s declared type, decoded from the 1-byte
RowDescriptionTypedtag (§9.2). An unrecognised tag (and0x00) maps toTypeTag::Unknown, treated asTEXT. - Value
- A decoded column value.
Traits§
- FromSql
- Read a column
Valueback into a Rust type. - ToSql
- Bind a Rust value as a positional
$nparameter. Parameters travel in text format (§10.4);Noneis SQLNULL.
Functions§
- connect
- Open a connection from a
nusadb://[user[:password]@]host[:port]/databaseURL.
Type Aliases§
- Result
- The crate-wide result alias.