Skip to main content

Crate pgorm

Crate pgorm 

Source
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 FromRow trait
  • Minimal magic: Traits and macros only for boilerplate reduction
  • Transaction-friendly: pass a transaction anywhere a GenericClient is 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 pgorm usage.
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§

CheckedClient
A client wrapper that automatically checks SQL against registered schemas.
ColumnInfo
ColumnMeta
Column information for schema checking.
ColumnRef
Column reference extracted from SQL.
CompositeHook
A composite hook that runs multiple hooks in sequence.
CompositeMonitor
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).
InstrumentedClient
An instrumented database client that wraps a GenericClient with monitoring.
Json
A wrapper type to allow arbitrary Serialize/Deserialize types to convert to Postgres JSON values.
LintIssue
A lint issue found in SQL.
LintResult
Result of linting a SQL query.
LoggingMonitor
A logging monitor that prints queries to stderr.
ModelCheckResult
Result of checking a model against the database schema.
MonitorConfig
Configuration for query monitoring and timeouts.
NoopMonitor
A no-op monitor that does nothing.
OrderBy
ORDER BY clause builder.
Pagination
Pagination configuration for LIMIT/OFFSET.
ParseResult
Result of SQL parsing/validation.
PgClient
Unified Postgres client with monitoring and SQL checking.
PgClientConfig
Configuration for PgClient.
PoolClient
Wrapper for deadpool_postgres::Client.
Query
A SQL string with pre-numbered placeholders ($1, $2, ...) plus bound parameters.
QueryContext
Context information about the query being executed.
QueryStats
Collected query statistics.
SchemaCache
SchemaCacheConfig
SchemaIssue
A schema validation issue.
SchemaRegistry
Registry for table schemas.
Sql
A SQL-first, parameter-safe dynamic SQL builder.
SqlCheckIssue
SqlPolicy
Policy for runtime SQL safety rules.
StatsMonitor
A monitor that tracks query statistics.
TableInfo
TableSchema
Table information for schema checking.
WriteReport
Report returned by insert_graph_report / update_by_id_graph_report.
WriteStepReport
Statistics for a single step in a write graph.

Enums§

CheckError
Error type for pgorm-check operations.
CheckMode
Check mode configuration for CheckedClient.
DangerousDmlPolicy
HookAction
Action to take after a hook processes a query.
IdentPart
A part of a SQL identifier.
LintLevel
Lint level for issues found.
NullsOrder
NULLS ordering for ORDER BY.
Op
Query operator for building conditions.
OrderItem
A single ORDER BY item.
OrmError
Error types for database operations
QueryResult
Result of a query execution for monitoring purposes.
QueryType
The type of SQL operation being performed.
RelationKind
SchemaCacheLoad
SchemaIssueKind
Kind of schema issue.
SchemaIssueLevel
Level of a schema issue.
SelectWithoutLimitPolicy
SortDir
Sort direction for ORDER BY.
SqlCheckIssueKind
SqlCheckLevel
StatementKind
Type of SQL statement.
WhereExpr
A WHERE clause expression tree supporting AND/OR/NOT/grouping.

Traits§

CheckClient
A trait for types that can execute PostgreSQL queries.
FromRow
Trait for converting a database row into a Rust struct.
GenericClient
A trait that unifies database clients and transactions.
IntoIdent
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.
QueryHook
Trait for hooking into the query execution lifecycle.
QueryMonitor
Trait for monitoring SQL query execution.
RowExt
Extension trait for Row to provide typed access
TableMeta
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::ManagerConfig and PoolBuilder.
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§

CheckResult
Result type for pgorm-check operations.
OrmResult
Result type alias for pgorm operations

Derive Macros§

FromRow
Derive FromRow trait for a struct.
InsertModel
Derive InsertModel helpers for inserting into a table.
Model
Derive Model metadata for a struct.
QueryParams
Derive QueryParams helpers for building dynamic queries from a params struct.
UpdateModel
Derive UpdateModel helpers for updating a table (patch-style).
ViewModel
Derive ViewModel metadata for a struct.