atrg-db
Database layer for at-rust-go: SQLite and PostgreSQL connection pooling and migrations.
Part of at-rust-go (atrg) — a batteries-included AT Protocol backend framework for Rust.
What this crate provides
DbPool— enum wrapping eithersqlx::SqlitePoolorsqlx::PgPool, the primary database handle used throughout atrgconnect(url)— create a connection pool, dispatching by URL scheme (sqlite://,sqlite::memory:,postgres://,postgresql://)run_internal_migrations(pool)— apply atrg's own embedded migrations (sessions table, etc.) using the dialect matching the pool variant; idempotent on every startuprun_user_migrations(pool, dir)— discover and apply application-specific.sqlmigrations from a directory, silently skipping if the directory is missing or empty
The crate does not provide an ORM. Write SQL with sqlx.
Cargo features
| Feature | Default | Effect |
|---|---|---|
sqlite |
✅ | Pulls in the sqlx/sqlite driver and enables DbPool::Sqlite. |
postgres |
❌ | Pulls in the sqlx/postgres driver and enables DbPool::Postgres. |
At least one of sqlite or postgres must be enabled (a compile_error! fires otherwise). Enabling both is supported; connect() picks the backend at runtime from the URL scheme.
Usage
[]
# SQLite only (default)
= "0.1"
# PostgreSQL only
= { = "0.1", = false, = ["postgres"] }
# Both backends — let `connect()` choose at runtime
= { = "0.1", = ["postgres"] }
use DbPool;
async
Connection defaults
SQLite
| Setting | Value |
|---|---|
| Journal mode | WAL |
| Foreign keys | ON |
| Create if missing | Yes |
| Max connections | 8 |
PostgreSQL
| Setting | Value |
|---|---|
| Max connections | 8 |
Migration conventions
atrg's internal migrations live in this crate under migrations/sqlite/ and migrations/postgres/. The set matching the active DbPool variant is run automatically. User migrations live in your project's migrations/ directory and are applied in filename order against the same backend:
migrations/
├── 0001_create_posts.sql
└── 0002_create_follows.sql
License
LGPL-3.0-only — see LICENSE.