Expand description
Postgres toolkit for Rust, powered by facet reflection.
This crate provides:
- Database migrations as Rust functions
- Schema introspection via facet reflection
- Query building (planned)
§Naming Convention
Table names use singular form (e.g., user, post, comment).
This convention treats each table as a definition of what a single record
represents, rather than a container of multiple records. It reads more
naturally in code: User::find(id) returns “a user”, and foreign keys
like author_id reference “the user table”.
Junction tables for many-to-many relationships use singular forms joined
by underscore: post_tag, post_like, user_follow.
§Migrations
Migrations are registered using the #[dibs::migration] attribute.
The version is automatically derived from the filename:
// In file: src/migrations/m_2026_01_17_120000_create_user.rs
#[dibs::migration]
async fn migrate(ctx: &mut MigrationContext) -> MigrationResult<()> {
ctx.execute("CREATE TABLE user (id SERIAL PRIMARY KEY, name TEXT NOT NULL)").await?;
Ok(())
}Use MigrationResult instead of Result to enable #[track_caller] - when an
error occurs, the exact source location (file:line:column) is captured.
Run migrations with MigrationRunner:
let runner = MigrationRunner::new(&client);
runner.migrate().await?;Re-exports§
pub use backoffice::SquelServiceImpl;pub use diff::Change;pub use diff::SchemaDiff;pub use diff::TableDiff;pub use meta::create_meta_tables_sql;pub use meta::record_migration_sql;pub use meta::sync_tables_sql;pub use pool::ConnectionProvider;pub use service::DibsServiceImpl;pub use service::run_service;pub use inventory;
Modules§
- backoffice
- Squel service implementation - the data plane.
- diff
- Schema diffing - compare Rust-defined schema against database schema.
- introspect
- Database introspection - read schema from a live Postgres database.
- meta
- Meta tables for schema provenance tracking.
- pool
- Connection pooling abstractions.
- query
- Query builder for dibs.
- schema
- Schema definition and introspection.
- service
- Dibs service implementation.
- solver
- Migration solver - orders and validates schema changes.
Macros§
- __
facet_ invoke - Plugin chain entry point.
Structs§
- Applied
Migration - A migration that was already applied.
- Change
Info - A single schema change.
- Check
- CHECK constraint definition.
- Check
Constraint - A table CHECK constraint.
- Column
- A database column definition.
- Column
Info - Column information.
- Composite
Index - Composite index definition for multi-column indices.
- Composite
Unique - Composite unique constraint for multi-column uniqueness.
- Create
Request - Request to create a new row.
- Delete
Request - Request to delete a row.
- Dibs
Service Client - Client for the
DibsServiceservice. - Dibs
Service Dispatcher - Dispatcher for this service.
- Diff
Request - Request to diff schema against a database.
- Diff
Result - Full diff result.
- Filter
- A single filter condition.
- Foreign
Key - A foreign key constraint.
- Foreign
KeyInfo - Foreign key information.
- Generated
Code - Generated Rust code for a query file.
- GetRequest
- Request to get a single row by primary key.
- Index
- A database index.
- Index
Column - A column in an index with optional sort order and nulls ordering.
- Index
Column Info - A column in an index with optional sort order and nulls ordering.
- Index
Info - Index information.
- Jsonb
- A wrapper type for PostgreSQL JSONB columns.
- List
Request - Request to list rows from a table.
- List
Response - Response from listing rows.
- Migrate
Request - Request to run migrations.
- Migrate
Result - Result of running migrations.
- Migration
- A registered migration.
- Migration
Context - Context passed to migration functions.
- Migration
Error - Error type for migrations that captures caller location via
#[track_caller]. - Migration
Info - Migration status.
- Migration
Log - Log message streamed during migration.
- Migration
Runner - Runs migrations against a database.
- Migration
Status - Status of a single migration.
- Migration
Status Request - Request to get migration status.
- Query
File - A query file - top level is a map of declaration names to declarations.
Uses
Meta<String>as keys to capture doc comments from the styx file. - RanMigration
- A migration that was just run.
- Row
- A row of data as field name → value pairs.
- RowField
- A single field in a row.
- Schema
- A complete database schema.
- Schema
Info - The full schema (list of tables).
- Sort
- A sort clause.
- Source
Location - Source location of a schema element.
- SqlError
- SQL error with context for rich error display.
- SqlError
Context - Rich SQL error with context for display.
- Squel
Service Client - Client for the
SquelServiceservice. - Squel
Service Dispatcher - Dispatcher for this service.
- Table
- A database table definition.
- Table
Def - A registered table definition.
- Table
Diff Info - Diff result for a single table.
- Table
Info - Schema information for a table.
- Traced
Conn - A wrapper around a database connection that logs all queries via tracing.
- Traced
Object - A traced connection that owns the underlying connection.
- Traced
Pool - A traced connection pool.
- Trigger
Check - Trigger-enforced check definition.
- Trigger
Check Constraint - A trigger-enforced invariant check (BEFORE INSERT OR UPDATE).
- Update
Request - Request to update a row.
Enums§
- Attr
- Dibs schema attribute types.
- Change
Kind - Kind of schema change.
- Dibs
Error - Error from the dibs service.
- Error
- Filter
Op - Filter operator for backoffice queries.
- LogLevel
- Log level.
- Nulls
Order - Nulls ordering for index columns.
- PgType
- Postgres column types.
- SortDir
- Sort direction.
- Sort
Order - Sort order for index columns.
- Value
- A runtime value for backoffice queries.
Traits§
- Connection
- Trait for database connections that can execute queries.
- Connection
Ext - Extension trait to get a traced wrapper from a connection.
- Dibs
Service - The dibs service trait.
- Squel
Service - The Squel service trait - the data plane.
Functions§
- build_
queries - Generate query code from a
.styxfile. - check_
constraint_ name - Generate a deterministic CHECK constraint name for a table and expression.
- dibs_
service_ service_ descriptor - generate_
rust_ code - Generate Rust code for a query file.
- index_
name - Generate a standard index name for a table and columns.
- parse_
query_ file - Parse a styx source string into a QueryFile.
- quote_
ident - Quote a PostgreSQL identifier.
- squel_
service_ service_ descriptor - trigger_
check_ function_ name - Derive the trigger function name for a trigger-enforced check.
- trigger_
check_ name - Generate a deterministic trigger name for a trigger-enforced check.
- unique_
index_ name - Generate a standard unique index name for a table and columns.
Type Aliases§
- Migration
Fn - Type alias for migration functions.
- Migration
Result - Result type for migration functions, captures caller location on error.
- Result
- Result type for dibs operations.
Attribute Macros§
- migration
- Register a migration function.