Expand description
PostgreSQL pooling, migrations, and test resets over sqlx.
This crate holds the operations every service repeats. It does not wrap
queries: a service writes its own SQL with sqlx::query!, so a reviewer
reads exactly what runs.
use axa_sqlx::{PoolConfig, connect, migrate, sqlx};
static MIGRATOR: sqlx::migrate::Migrator = sqlx::migrate::Migrator::DEFAULT;
let pool = connect(&PoolConfig::new("postgres://localhost/app")).await?;
migrate(&pool, &MIGRATOR).await?;Re-exports§
pub use sqlx;
Structs§
- Migration
Status - One migration and whether it has run.
- Pool
Config - Pool settings.
Enums§
- Conn
- A connection for the length of one call. It derefs to
PgConnection. - Db
- Where a function gets its connection: the pool, or a connection the caller holds, usually an open transaction, so one function serves both.
Functions§
- connect
- Open a pool and prove it works with one connection.
- dangerously_
recreate - Drop every table and enum type in
public, then migrate from nothing. This gives each test an empty schema, whatever tables it touched. - is_
unique_ violation - Whether an error is a violated unique constraint, which a service usually
reports as
409rather than500. - migrate
- Apply pending migrations. Sqlx holds a lock while it does, so services booting together take turns.
- ping
- Check that the database answers.
- quote_
identifier - Quote a table or type name for use in SQL.
- revert
- Revert the newest
stepsmigrations. Each needs a.down.sqlfile. - status
- Every migration in
migrator, oldest first, with whether it has run. - truncate
- Empty
tables, restarting their sequences. Each name goes throughquote_identifier.