sentinel
Compile-time guarded ORM for PostgreSQL — your data's guardian from compile to production.
N+1 queries, over-fetching, unsafe relation access — caught at compile time, not production.
Quick Start
[]
= "0.1"
use *;
async
Compile-time SQL validation
Sentinel ships an sqlx-style query!() family that pulls types from a checked-in
.sentinel/ cache. The schema and per-query metadata are produced by sntl prepare
against a live PostgreSQL, then committed alongside the code so CI builds work
offline.
use Connection;
async
Bypass the cache temporarily with sntl::query_unchecked! / query_as_unchecked!,
or load SQL from disk with sntl::query_file! / query_file_as!.
The companion CLI provides:
Compared to sqlx: the offline cache is the source of truth (no DATABASE_URL required
at compile time); pipelined batches are first-class; nullable inference can be
overridden per-call with nullable = [...] / non_null = [...].
See docs/migration-from-sqlx.md for a side-by-side migration guide.
Features
- Compile-time guards — N+1, over-fetching, and unsafe relation access caught before runtime
- Type-state relations —
User<Bare>vsUser<WithPosts>, compile error on unloaded access - Partial types —
#[derive(Partial)]generates narrow select types, no over-fetching - Reducer pattern —
#[reducer]for transactions with auto-commit/rollback - Deadlock prevention — auto-reorder locks by ID
- 4-layer query system — from simple CRUD to raw SQL, always type-safe, always parameterized
- Zero unsafe in core — security by construction
- Built on sentinel-driver — SCRAM-SHA-256, pipeline mode, binary format, rustls
- Production observability — single
Instrumentationtrait hooks every wire site and every macro invocation; ships with a tracing/OTel adapter (seedocs/observability-guide.md)
Architecture
sentinel/
├── sntl # Main crate — models, queries, transactions, types, query! family
├── sntl-macros # Proc macros — derive(Model), derive(Partial), derive(FromRow), query!()
├── sntl-schema # Shared SQL parsing, nullability, and .sentinel/ cache I/O
├── sntl-cli # CLI binary — `sntl prepare`, `sntl check`, `sntl doctor`, `sntl migrate ...`
├── sntl-migrate # Forward-only migrations + schema-diff scaffolder (v0.3)
└── sntl-core # Core traits extraction (planned)
sntl,sntl-macros,sntl-schema,sntl-cli, andsntl-migrateare implemented today. Seedocs/migration-guide.mdfor thesntl-migrateuser guide.
sntl-coreis published on crates.io as a name reservation and will be filled in in a future release.Observability (v0.4+):
sntlshipssntl::observability::SntlTracing, a bridge oversentinel-driverv3.0+'sInstrumentationtrait. It hooks every wire-trip and everyquery!()/ migration call — feedingdb.system,sntl.macro, andsntl.query_idinto anytracing-compatible backend (Jaeger, Zipkin, OTLP). Seedocs/observability-guide.md.
Development
MSRV
Rust 1.85 (declared via rust-version in Cargo.toml).
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT License (LICENSE-MIT)
at your option.