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.

It has the same shape as axa-seaorm, axa-diesel, and axa-toasty: a Pool, a PoolConfig, connect, ping, migrate, revert, pending, truncate, dangerously_recreate, is_unique_violation, and quote_identifier, with status besides.

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.

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 409 rather than 500.
migrate
Apply pending migrations. Sqlx holds a lock while it does, so services booting together take turns.
pending
The names of the migrations in migrator not yet applied, in order, each as version_description.
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.

Type Aliases§

Error
What this crate’s connection and query functions return on failure.
Pool
The handle a service holds: the pool.