let db = Database::connect("postgres://...").await?;Customize sqlx pool options when needed:
let db = Database::connect_with_options(
"postgres://...",
dbkit::PgPoolOptions::new().max_connections(20),
)
.await?;Migrations are optional and use sqlx:
# Cargo.toml
dbkit = { version = "0.3", features = ["migrations"] }use dbkit::{Database, migrate::Migrator};
static MIGRATOR: Migrator = dbkit::sqlx::migrate!("./migrations");
let db = Database::connect("postgres://...").await?;
db.migrate(&MIGRATOR).await?;dbkit keeps migration execution thin and delegates migration file parsing/running to sqlx.
let tx = db.begin().await?;
let users = User::query().all(&tx).await?;
tx.commit().await?;let tx = db.begin().await?;
tx.set_local("statement_timeout", "5s").await?;
let users = User::query()
.filter(User::email.like("%@example.com"))
.all(&tx)
.await?;
tx.commit().await?;set_local uses PostgreSQL set_config(..., true), so the setting is scoped to the current transaction
instead of leaking across pooled connection reuse.