Skip to main content

Crate axa_sqlx

Crate axa_sqlx 

Source
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§

MigrationStatus
One migration and whether it has run.
PoolConfig
Pool settings.

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 409 rather than 500.
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 steps migrations. Each needs a .down.sql file.
status
Every migration in migrator, oldest first, with whether it has run.
truncate
Empty tables, restarting their sequences. Each name goes through quote_identifier.