Skip to main content

Crate lattice_sql_client

Crate lattice_sql_client 

Source
Expand description

§lattice-sql-client

Typed Rust SDK for lattice-sql — the SQL frontend for lattice-db.

Sends SQL strings to the ldb.sql.query NATS subject and maps the JSON responses back to strongly-typed Rust values.

§Quick start

use nats_wasip3::client::{Client, ConnectConfig};
use lattice_sql_client::LatticeSql;

let client = Client::connect(ConnectConfig::default()).await?;
let db = LatticeSql::new(client)
    .with_auth("my-token"); // matches LDB_AUTH_TOKEN on the server

// DDL — create a table
db.ddl("CREATE TABLE users (id TEXT PRIMARY KEY, name TEXT NOT NULL, age INTEGER)").await?;

// DML — insert rows
let affected = db.exec("INSERT INTO users (id, name, age) VALUES ('alice', 'Alice', 30)").await?;
assert_eq!(affected, 1);

// Query — SELECT with filters, sorting, pagination
let result = db.query("SELECT * FROM users WHERE age >= 25 ORDER BY name ASC LIMIT 10").await?;
println!("columns: {:?}", result.columns);
for row in &result.rows {
    println!("{:?}", row);
}

// Lookup a cell by column name
if let Some(name) = result.cell(0, "name") {
    println!("first row name: {name}");
}

// Aggregates
let agg = db.query("SELECT COUNT(*), SUM(age) FROM users").await?;
let count = &agg.rows[0][0]; // COUNT(*)

// Cleanup
db.ddl("DROP TABLE users").await?;

Structs§

LatticeSql
Typed client for the lattice-sql SQL frontend.
QueryResult
The result of a SELECT query.

Enums§

Error
Errors returned by the lattice-sql client.
SqlResult
The auto-detected result of any SQL statement sent via LatticeSql::sql.