Skip to main content

Crate prax_postgres

Crate prax_postgres 

Source
Expand description

§prax-postgres

PostgreSQL driver for the Prax ORM with connection pooling and prepared statement caching.

This crate provides:

  • Connection pool management using deadpool-postgres
  • Prepared statement caching for improved performance
  • Type-safe parameter binding
  • Row deserialization into Prax models
  • PgListener: LISTEN / NOTIFY on a dedicated, auto-reconnecting connection, with PgConnection::notify / PgTransaction::notify for sending (any role can NOTIFY any channel, so treat payloads as untrusted)
  • Pool recycling policy (PgRecycling: Fast (default), Verified, Clean), bounded by PoolConfig::recycle_timeout, plus jittered max_lifetime retirement. Fast keeps session state (SET ROLE, search_path, tenant GUCs) across checkouts; use Clean when that matters
  • Row locking (FOR UPDATE / FOR SHARE, SKIP LOCKED, NOWAIT, OF) through PgEngine and prax_query’s .lock(RowLock); OF table names must be plain identifiers
  • Typed array binding for FilterValue::Array (use = ANY($1)) and raw bytea for FilterValue::Bytes

§Example

ⓘ
use prax_postgres::PgPool;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create a connection pool
    let pool = PgPool::builder()
        .url("postgresql://user:pass@localhost/db")
        .max_connections(10)
        .build()
        .await?;

    // Get a connection
    let conn = pool.get().await?;

    Ok(())
}

Re-exports§

pub use config::PgConfig;
pub use config::PgConfigBuilder;
pub use connection::PgConnection;
pub use engine::PgEngine;
pub use error::PgError;
pub use error::PgResult;
pub use listener::PgListener;
pub use listener::PgListenerBuilder;
pub use listener::PgListenerEvent;
pub use listener::PgListenerOptions;
pub use listener::PgNotification;
pub use pool::PgPool;
pub use pool::PgPoolBuilder;
pub use pool::PgRecycling;
pub use pool::PoolConfig;
pub use pool::PoolStatus;
pub use row::PgRow;
pub use statement::PreparedStatementCache;

Modules§

config
PostgreSQL connection configuration.
connection
PostgreSQL connection wrapper.
deserialize
Row -> T: FromRow helpers for PgEngine.
engine
PostgreSQL query engine implementation.
error
Error types for PostgreSQL operations.
listener
LISTEN / NOTIFY on a dedicated connection.
pool
Connection pool for PostgreSQL.
prelude
Prelude for convenient imports.
row
PostgreSQL row types and deserialization.
row_ref
Bridge between tokio_postgres::Row and prax_query::row::RowRef.
statement
Prepared statement caching.
tls
TLS connector construction for the connection pool, via rustls.
types
Type conversions for PostgreSQL.

Macros§

impl_from_row
Macro to implement FromPgRow for simple structs.