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 responses back to strongly-typed Rust values. Sits above lattice-db-client in the stack: you write SQL, not raw key-value operations.
Requirements
- Target:
wasm32-wasip3(Component Model async I/O) - Toolchain: Rust nightly with
-Zbuild-std - Runtime: wasmCloud ≥ 2.0, or Wasmtime ≥ 45
- Services: A running
storage-serviceand a runninglattice-sqlinstance, both connected to NATS
Quick start
Add to your Cargo.toml:
[]
= "1.0"
= "0.7"
use ;
use LatticeSql;
let client = connect.await?;
// Optional: auth token (required when server sets LDB_AUTH_TOKEN)
let db = new
.with_auth;
// DDL — define a table
db.ddl.await?;
// DML — write data
db.exec.await?;
db.exec.await?;
// Query — read data
let result = db.query.await?;
println!; // ["id", "name", "age"]
// Cell access by column name
let name = result.cell.unwrap; // "Alice"
// Aggregate
let agg = db.query.await?;
let count = agg.rows.as_i64.unwrap; // 1
// Deserialize rows into a struct
let users: = result.deserialize_rows?;
// Cleanup
db.ddl.await?;
Supported SQL
| Statement | Example |
|---|---|
CREATE TABLE |
CREATE TABLE t (id TEXT PRIMARY KEY, x INTEGER) |
CREATE TABLE IF NOT EXISTS |
CREATE TABLE IF NOT EXISTS t (...) |
DROP TABLE |
DROP TABLE t |
DROP TABLE IF EXISTS |
DROP TABLE IF EXISTS t |
CREATE INDEX |
CREATE INDEX ON t (field) |
DROP INDEX |
DROP INDEX field |
INSERT INTO |
INSERT INTO t (id, x) VALUES ('k', 42) |
UPDATE |
UPDATE t SET x = 99 WHERE id = 'k' |
DELETE |
DELETE FROM t WHERE x < 10 |
SELECT * |
SELECT * FROM t |
SELECT cols |
SELECT id, name FROM t |
WHERE |
WHERE age > 25 AND city = 'Helsinki' |
ORDER BY |
ORDER BY name ASC |
LIMIT / OFFSET |
LIMIT 10 OFFSET 20 |
| Aggregates | SELECT COUNT(*), SUM(x), AVG(x), MIN(x), MAX(x) FROM t |
GROUP BY |
SELECT region, COUNT(*) FROM t GROUP BY region |
INNER JOIN |
SELECT a.id, b.val FROM a INNER JOIN b ON a.id = b.fk |
LEFT JOIN |
SELECT a.id, b.val FROM a LEFT JOIN b ON a.id = b.fk |
Column types
| SQL type | JSON representation |
|---|---|
TEXT / VARCHAR |
string |
INTEGER / INT |
number (integer) |
REAL / FLOAT |
number (float) |
BOOLEAN |
boolean |
API
LatticeSql
QueryResult
SqlResult (auto-detected)
Error
Building
Running the smoke test
# Start dependencies
&
&
&
# Build and run
Integration tests
A bash integration test for the SQL frontend is also available at the workspace level:
# With custom NATS:
NATS_URL=host:4222
# With mTLS:
Architecture
Your code
│ SQL string
▼
LatticeSql (this crate)
│ {"sql":"..."} over NATS → ldb.sql.query
▼
lattice-sql (SQL frontend component)
│ ldb.get / ldb.scan / ldb.put / …
▼
storage-service (lattice-db)
│ JetStream KV
▼
NATS Server
License
Apache-2.0