Skip to main content

Crate nusadb

Crate nusadb 

Source
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 over Connection. It emits NusaDB’s own SQL (double-quoted identifiers, $n parameters, constant LIMIT/OFFSET, RETURNING *) and decodes rows into user types via FromRow. Select covers 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 with Connection::query / Connection::query_params.

Structs§

CancelHandle
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/NOTIFY notification delivered by the server (§ pub/sub). Collected by the connection while it is idle and returned from Connection::notifications / Connection::poll_notification.
Pool
A pool of NusaDB connections sharing one Config.
PooledConnection
A connection checked out of a Pool. Derefs to Connection; returns to the pool on drop unless PooledConnection::discard was called.
Prepared
A prepared statement: a name the server holds a parsed plan under, reusable across executions.
QueryResult
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 nusadb driver error.
TypeTag
A column’s declared type, decoded from the 1-byte RowDescriptionTyped tag (§9.2). An unrecognised tag (and 0x00) maps to TypeTag::Unknown, treated as TEXT.
Value
A decoded column value.

Traits§

FromSql
Read a column Value back into a Rust type.
ToSql
Bind a Rust value as a positional $n parameter. Parameters travel in text format (§10.4); None is SQL NULL.

Functions§

connect
Open a connection from a nusadb://[user[:password]@]host[:port]/database URL.

Type Aliases§

Result
The crate-wide result alias.