spg-sqlx
sqlx 0.8 Database driver for [spg-embedded]. Lets
in-process callers swap sqlx::PgPool for SpgPool and keep
the rest of their sqlx::query / sqlx::query_as /
pool.begin cement unchanged — backs mailrs's drop-in
"PgPool → SpgPool" goal from the gap evaluation (E1).
v7.16.0 MVP scope
- [
Spg] marker type + the 11 associated typessqlx::Databaserequires, all wired up to compile. - [
SpgPool] / [SpgConnection] wrap [spg_embedded_tokio::AsyncDatabase] so a single in-process database is the "pool". No real pooling — every "connection" handle is a cheap clone of the underlyingArc<Mutex<Database>>. - Bind-time [
Value][SpgValue] encoding for the basic scalar surface:i32,i64,bool,String,Vec<u8>. Round-trip verified end-to-end againstsqlx::query("INSERT …").bind(…)in the test suite. - Transactions via the engine's BEGIN/COMMIT/ROLLBACK; the
[
SpgTransactionManager] wraps that forpool.begin().
v7.16.x / v7.17 follow-up
- Encode/Decode for the remaining mailrs-side types:
TIMESTAMPTZ (
chrono::DateTime<Utc>), JSON / JSONB (serde_json::Value),tsvector,VECTOR(N),INT[]/TEXT[],BYTEA(Vec beyond the basic path), numeric. FromRowderive support — the macro's generated impl reads columns by index/name via the [Row][sqlx_core::row::Row] trait, so wiringSpgRow::try_getis enough for the derive to "just work" once the per-type Decode lands.sqlx::query!()compile-time validation via sqlx's offline mode (SQLX_OFFLINE=true+ a checked-in.sqlx/dir). The adapter itself doesn't need a DESCRIBE protocol —Spg-shaped offline cache mirrors what mailrs ships against PG today.
Quick start
use spg_sqlx::{SpgPool, SpgPoolExt};
# async fn _f() -> Result<(), Box<dyn std::error::Error>> {
let pool = SpgPool::connect_in_memory().await?;
sqlx::query("CREATE TABLE users (id INT NOT NULL, name TEXT NOT NULL)")
.execute(&pool)
.await?;
sqlx::query("INSERT INTO users VALUES ($1, $2)")
.bind(1_i32)
.bind("alice")
.execute(&pool)
.await?;
# Ok(())
# }