Expand description
§pgorm
A lightweight Postgres-only ORM for Rust.
§Features
- SQL explicit: SQL is a first-class citizen (use
query()/sql();qb::query()is an alias) - Type-safe mapping: Row → Struct via
FromRowtrait - Minimal magic: Traits and macros only for boilerplate reduction
- Transaction-friendly: pass a transaction anywhere a
GenericClientis expected - Query monitoring: Built-in support for timing, logging, and hooking SQL execution
- SQL checking: Validate SQL against registered schemas and lint for common issues
- Migrations: Optional SQL migrations via
refinery(feature:migrate)
§SQL fallback (qb)
The qb module is a thin wrapper around query() for running hand-written SQL:
ⓘ
use pgorm::qb;
let users: Vec<User> = qb::query("SELECT * FROM users WHERE status = $1")
.bind("active")
.fetch_all_as(&client)
.await?;Re-exports§
pub use changeset::ValidationCode;pub use changeset::ValidationError;pub use changeset::ValidationErrors;pub use eager::BelongsToMap;pub use eager::HasManyMap;pub use eager::Loaded;
Modules§
- changeset
- Changeset-style validation error types.
- eager
- Eager loading (batch preloading for relations).
- prelude
- Convenient imports for typical
pgormusage. - qb
- Minimal facade for running hand-written SQL.
- validate
- Validation helpers used by derive-generated Input structs.
Macros§
- assert_
models_ db_ valid - Assert that all models match the database schema, panic if not.
- assert_
models_ valid - Check models and panic if any have schema issues.
- check_
models - Check multiple models against a schema registry and return results.
- check_
models_ db - Check models against the actual database schema.
- print_
model_ check - Print schema check results for multiple models.
- print_
models_ db_ check - Check models against database and print results.
- transaction
- Runs the given block inside a database transaction.
Structs§
- Checked
Client - A client wrapper that automatically checks SQL against registered schemas.
- Column
Info - Column
Meta - Column information for schema checking.
- Column
Ref - Column reference extracted from SQL.
- Composite
Hook - A composite hook that runs multiple hooks in sequence.
- Composite
Monitor - A composite monitor that delegates to multiple monitors.
- Condition
- A query condition primitive used by builders.
- DbSchema
- Ident
- A SQL identifier (column, table, or schema name).
- Instrumented
Client - An instrumented database client that wraps a
GenericClientwith monitoring. - Json
- A wrapper type to allow arbitrary
Serialize/Deserializetypes to convert to Postgres JSON values. - Lint
Issue - A lint issue found in SQL.
- Lint
Result - Result of linting a SQL query.
- Logging
Monitor - A logging monitor that prints queries to stderr.
- Model
Check Result - Result of checking a model against the database schema.
- Monitor
Config - Configuration for query monitoring and timeouts.
- Noop
Monitor - A no-op monitor that does nothing.
- OrderBy
- ORDER BY clause builder.
- Pagination
- Pagination configuration for LIMIT/OFFSET.
- Parse
Result - Result of SQL parsing/validation.
- PgClient
- Unified Postgres client with monitoring and SQL checking.
- PgClient
Config - Configuration for
PgClient. - Pool
Client - Wrapper for
deadpool_postgres::Client. - Query
- A SQL string with pre-numbered placeholders (
$1, $2, ...) plus bound parameters. - Query
Context - Context information about the query being executed.
- Query
Stats - Collected query statistics.
- Schema
Cache - Schema
Cache Config - Schema
Issue - A schema validation issue.
- Schema
Registry - Registry for table schemas.
- Sql
- A SQL-first, parameter-safe dynamic SQL builder.
- SqlCheck
Issue - SqlPolicy
- Policy for runtime SQL safety rules.
- Stats
Monitor - A monitor that tracks query statistics.
- Table
Info - Table
Schema - Table information for schema checking.
- Write
Report - Report returned by
insert_graph_report/update_by_id_graph_report. - Write
Step Report - Statistics for a single step in a write graph.
Enums§
- Check
Error - Error type for pgorm-check operations.
- Check
Mode - Check mode configuration for
CheckedClient. - Dangerous
DmlPolicy - Hook
Action - Action to take after a hook processes a query.
- Ident
Part - A part of a SQL identifier.
- Lint
Level - Lint level for issues found.
- Nulls
Order - NULLS ordering for ORDER BY.
- Op
- Query operator for building conditions.
- Order
Item - A single ORDER BY item.
- OrmError
- Error types for database operations
- Query
Result - Result of a query execution for monitoring purposes.
- Query
Type - The type of SQL operation being performed.
- Relation
Kind - Schema
Cache Load - Schema
Issue Kind - Kind of schema issue.
- Schema
Issue Level - Level of a schema issue.
- Select
Without Limit Policy - SortDir
- Sort direction for ORDER BY.
- SqlCheck
Issue Kind - SqlCheck
Level - Statement
Kind - Type of SQL statement.
- Where
Expr - A WHERE clause expression tree supporting AND/OR/NOT/grouping.
Traits§
- Check
Client - A trait for types that can execute PostgreSQL queries.
- FromRow
- Trait for converting a database row into a Rust struct.
- Generic
Client - A trait that unifies database clients and transactions.
- Into
Ident - Convert an input into an
Ident. - ModelPk
- Trait for models with a primary key.
- PgType
- Trait that maps Rust types to PostgreSQL type names for UNNEST casts.
- Query
Hook - Trait for hooking into the query execution lifecycle.
- Query
Monitor - Trait for monitoring SQL query execution.
- RowExt
- Extension trait for Row to provide typed access
- Table
Meta - Metadata for a database table.
Functions§
- check_
sql - check_
sql_ cached - create_
pool - Create a connection pool from a database URL.
- create_
pool_ with_ config - Create a connection pool with custom configuration
- create_
pool_ with_ manager_ config - Create a connection pool with injected
deadpool_postgres::ManagerConfigandPoolBuilder. - create_
pool_ with_ tls - Create a connection pool using a custom TLS connector.
- delete_
has_ where - Check if a DELETE query has a WHERE clause.
- detect_
statement_ kind - Detect the type of SQL statement.
- get_
column_ refs - Get all column references from a SQL query.
- get_
table_ names - Get all table names referenced in a SQL query.
- is_
valid_ sql - Check if a SQL string is syntactically valid.
- lint_
select_ many - Lint a SELECT query specifically for “select many” patterns.
- lint_
sql - Lint a SQL query for common issues.
- load_
schema_ from_ db - query
- Build a SQL query from a pre-numbered SQL string (
$1, $2, ...). - select_
has_ limit - Check if a SELECT query has a LIMIT clause.
- select_
has_ star - Check if a SELECT query uses SELECT *.
- sql
- Start building a SQL statement.
- update_
has_ where - Check if an UPDATE query has a WHERE clause.
Type Aliases§
- Check
Result - Result type for pgorm-check operations.
- OrmResult
- Result type alias for pgorm operations
Derive Macros§
- FromRow
- Derive
FromRowtrait for a struct. - Insert
Model - Derive
InsertModelhelpers for inserting into a table. - Model
- Derive
Modelmetadata for a struct. - Query
Params - Derive
QueryParamshelpers for building dynamic queries from a params struct. - Update
Model - Derive
UpdateModelhelpers for updating a table (patch-style). - View
Model - Derive
ViewModelmetadata for a struct.