A3S ORM is a type-safe, executor-neutral SQL query builder for Rust, inspired by Kysely. Table declarations constrain columns, values, assignments, and decoded results at compile time. Immutable builders compile into SQL plus bound parameters, then execute through an async driver-neutral interface.
Despite the name, this is not an Active Record framework. Records do not own persistence behavior, queries remain visible, and runtime values are never interpolated into generated SQL.
The contract
Define the schema once, compose with typed columns, and inspect the exact query before it reaches a connection:
use ;
orm_table!
sql = select "person"."id", "person"."name" from "person" where ("person"."age" >= $1) order by "person"."name" asc limit $2
parameters = [I64(18), U64(20)]
Column ownership and Rust value families are checked before compilation. The dialect owns quoting, placeholders, and feature support; unsupported syntax is rejected instead of approximated.
Quick start
Install
SQLite is the default runtime. Pin the released Git tag:
[]
= { = "https://github.com/A3S-Lab/ORM", = "v0.3.0" }
= { = "1", = ["macros", "rt-multi-thread"] }
Enable the bundled PostgreSQL driver instead:
= { = "https://github.com/A3S-Lab/ORM", = "v0.3.0", = false, = ["postgres"] }
Or use the query builder and dialect compilers without a bundled runtime:
= { = "https://github.com/A3S-Lab/ORM", = "v0.3.0", = false }
The postgres feature includes UUID, JSON/JSONB, Chrono date/time types,
rust_decimal::Decimal, and SqlArray<T>.
Execute a typed SQLite round trip
The default feature is enough for a real in-memory database:
use ;
orm_table!
async
Capability map
- Typed structure — schema markers constrain columns, joins, filters, inserts, updates, and result decoding.
- Composable SQL — immutable SELECT, INSERT, UPDATE, and DELETE builders
cover joins, CTEs,
UPDATE FROM, typed expression assignments, subqueries, aggregates, windows, set operations, functions, casts, and conflict handling. - Explicit concurrency — PostgreSQL row locks, table locks, advisory locks, transaction isolation, access mode, and timeouts remain typed operations.
- Checked results — scalar, tuple, nullable, array, UUID, JSON, temporal, and decimal values decode through checked conversions.
- Cancellation-safe execution — scoped SQLite and PostgreSQL transactions retain their connection until rollback cleanup completes.
- Deterministic migrations — ordered, checksummed migrations run atomically behind a bounded database lock.
- Controlled escape hatch —
sql_query::<Output>accepts reviewed static SQL while dynamic values still enter throughbind.
PostgreSQL worker queues stay typed
Lock clauses, CTEs, update sources, and expression assignments are AST nodes rather than appended SQL strings. That keeps candidate selection and lease acquisition in one parameterized statement:
use ;
orm_table!
orm_table!
Transaction-scoped advisory_xact_lock(namespace, key) covers logical
resources that do not have a row yet. Retry classification identifies
serialization, deadlock, lock contention, failover, connection loss, and pool
saturation without automatically replaying writes. See
PostgreSQL HA Controls for the complete contract.
Drivers and dialects
| Capability | PostgreSQL | SQLite | MySQL |
|---|---|---|---|
| SQL compilation | Yes | Yes | Yes |
| Bundled async driver | Yes | Yes | No |
RETURNING |
Yes | Yes | Rejected |
ON CONFLICT |
Yes | Yes | Rejected |
UPDATE FROM |
Yes | Yes | Rejected |
| Row and table locks | Yes | Rejected | Rejected |
| Transactions | Yes | Yes | — |
| Locked migrations | Advisory lock | BEGIN IMMEDIATE |
— |
| UUID, JSON, temporal, decimal, arrays | Yes | SQLite-native subset | — |
SQLite uses a Tokio-safe single connection. File databases default to WAL, foreign-key enforcement, and a five-second busy timeout. Nested savepoints and scoped transactions prevent later work from racing cancellation cleanup.
PostgreSQL uses a bounded Deadpool pool with prepared-statement caching.
The driver exposes typed transaction policy, stable label-free health metrics,
retry classification, verified rustls connections, and health-gated atomic TLS
pool rotation. connect_no_tls is intended for local or separately secured
connections.
MySQL support currently means SQL generation only. It does not imply a bundled runtime driver. Read Production Readiness for the precise deployment scope and limitations.
Migrations
Migrations are sorted by version, checksummed with SHA-256, and recorded in
a3s_orm_migrations. Re-running an unchanged set is a no-op; modifying or
removing an applied migration is an error.
use ;
async
SQLite coordinates migrators through its connection gate and
BEGIN IMMEDIATE. PostgreSQL uses a transaction-scoped advisory lock with a
bounded deadline. Migration SQL and its history entry commit atomically.
Architecture
The query API does not depend on a database client:
typed schema + expressions
│
immutable query AST
│
dialect compiler
│
SQL + bound parameters
│
async Executor / driver
The compiler never opens a connection, and drivers never need to understand
typed builder state. A new dialect implements Dialect; a new runtime
implements Executor. See Architecture for module
ownership and extension rules.
Production boundaries
The library makes unsupported behavior visible rather than silently falling back:
- the bundled SQLite executor serializes work on one connection;
- MySQL has a compiler but no bundled runtime driver;
- migrations are forward-only;
- scalar function and cast result types are explicit caller assertions;
- typed DDL builders, query plugins, custom PostgreSQL domain codecs, and schema code generation are not included yet.
Review Production Readiness before deployment, PostgreSQL HA Controls for pool and failover policy, and the Roadmap for planned work.
Development
The test suite runs real SQLite databases and PostgreSQL 17 services. CI checks the feature matrix, compile-fail doctests, Rust 1.85 MSRV, strict Clippy, warning-free rustdoc, dependency advisories, and at least 90% line coverage.
RUSTDOCFLAGS="-D warnings"
To run PostgreSQL integration tests locally:
A3S_ORM_POSTGRES_URL=postgres://postgres:postgres@127.0.0.1:5432/a3s_orm \