Skip to main content

Crate puerto_sqlx

Crate puerto_sqlx 

Source
Expand description

The Postgres adapter every Puerto project with a database shares (ADR-0017): the connection pool, migrations at startup, the readiness ping and the one mapping from driver errors to RepositoryError.

The migrations are the project’s own: sqlx::migrate! embeds a directory at compile time, so the project declares its Migrator and hands it over. A generated infrastructure/src/db.rs is

ⓘ
pub use puerto_sqlx::*;

pub static MIGRATOR: sqlx::migrate::Migrator = sqlx::migrate!("./migrations");

and its repositories call crate::db::map_sqlx_error.

Enums§

DatabaseError
Why the database could not be used at startup.

Functions§

create_postgres_pool
map_sqlx_error
The one place that knows Postgres error codes: a driver error, as the repository port speaks it. The caller logs it first, with its own context.
ping
Whether the database answers a trivial query — what /health/ready reports.
run_migrations
Applies the project’s pending migrations — migrator is its sqlx::migrate!("./migrations").