Expand description
§pgorm
A model-definition-first, AI-friendly PostgreSQL ORM for Rust.
§Quick Start
ⓘ
use pgorm::prelude::*;§Two-level API
- Recommended:
PgClient— monitoring + SQL checking + statement cache + policy - Low-level:
GenericClient/Sql— pluggable, minimal abstraction
§Modules
monitor— query monitoring, hooks, [InstrumentedClient]check— SQL schema checking, linting,SchemaRegistryprelude— convenientuse pgorm::prelude::*for daily useqb— thin wrapper aroundquery()for hand-written SQL
Stability: pgorm is pre-1.0. APIs may change between minor versions. MSRV: 1.88+
Re-exports§
pub use types::Bound;pub use types::Range;pub use eager::BelongsToMap;pub use eager::HasManyMap;pub use eager::HasOneMap;pub use eager::Loaded;pub use changeset::ValidationCode;pub use changeset::ValidationError;pub use changeset::ValidationErrors;pub use check::ColumnMeta;pub use check::SchemaRegistry;pub use check::TableMeta;pub use check::TableSchema;pub use tokio_postgres;
Modules§
- changeset
- Changeset-style validation error types.
- check
- SQL schema checking and linting utilities.
- eager
- Eager loading (batch preloading for relations).
- monitor
- Query monitoring and hooks for SQL execution.
- prelude
- Convenient imports for typical
pgormusage. - qb
- Minimal facade for running hand-written SQL.
- types
- PostgreSQL special types.
- 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.
- nested_
transaction - Runs the given block inside a nested transaction (savepoint).
- print_
model_ check - Print schema check results for multiple models.
- print_
models_ db_ check - Check models against database and print results.
- savepoint
- Runs the given block inside a savepoint within an existing transaction.
- transaction
- Runs the given block inside a database transaction.
Structs§
- Condition
- A query condition primitive used by builders.
- Delete
Many Builder - Builder for bulk DELETE operations.
- From
RowStream - Ident
- A SQL identifier (column, table, or schema name).
- Json
- A wrapper type to allow arbitrary
Serialize/Deserializetypes to convert to Postgres JSON values. - Keyset1
- Single-column keyset pagination builder.
- Keyset2
- Two-column keyset pagination builder (primary key + tie-breaker).
- Model
Check Result - Result of checking a model against the database schema.
- OrderBy
- ORDER BY clause builder.
- Pagination
- Pagination configuration for LIMIT/OFFSET.
- 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. - RowStream
- A stream of database rows.
- Savepoint
- A named savepoint within a transaction.
- Sql
- A parameter-safe dynamic SQL builder.
- SqlPolicy
- Policy for runtime SQL safety rules.
- Statement
Cache Config - Prepared statement cache configuration (per-connection).
- Stmt
Cache Stats - Statement cache statistics.
- Update
Many Builder - Builder for bulk UPDATE operations.
- With
Builder - Builder for CTE (WITH clause) queries.
- 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
Mode - Check mode configuration for
CheckedClient. - Cursor
- Cursor position for keyset pagination.
- Dangerous
DmlPolicy - Ident
Part - A part of a SQL identifier.
- 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.
- Select
Without Limit Policy - SetExpr
- A SET clause expression for bulk updates.
- SortDir
- Sort direction for ORDER BY.
- Where
Expr - A WHERE clause expression tree supporting AND/OR/NOT/grouping.
Traits§
- 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.
- RowExt
- Extension trait for Row to provide typed access
- Streaming
Client - Streaming query support (RowStream).
- Transaction
Ext - Extension trait adding savepoint support to transactions.
Functions§
- 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.
- query
- Build a SQL query from a pre-numbered SQL string (
$1, $2, ...). - sql
- Start building a SQL statement.
Type Aliases§
- 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. - PgComposite
- Derive
PgCompositehelpers to map a Rust struct to a PostgreSQL composite type. - PgEnum
- Derive
PgEnumhelpers to map a Rust enum to a PostgreSQL ENUM type. - 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.