Skip to main content

Crate spg_sqlx

Crate spg_sqlx 

Source
Expand description

§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 types sqlx::Database requires, 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 underlying Arc<Mutex<Database>>.
  • Bind-time Value encoding for the basic scalar surface: i32, i64, bool, String, Vec<u8>. Round-trip verified end-to-end against sqlx::query("INSERT …").bind(…) in the test suite.
  • Transactions via the engine’s BEGIN/COMMIT/ROLLBACK; the SpgTransactionManager wraps that for pool.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.
  • FromRow derive support — the macro’s generated impl reads columns by index/name via the Row trait, so wiring SpgRow::try_get is 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};

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?;

Structs§

Spg
sqlx 0.8 driver for spg-embedded.
SpgArgumentValue
One bound argument. Wraps the engine-side value plus its fixed SpgTypeInfo so the engine’s executor sees a pre-coerced value (matches the engine’s Expr::Placeholderparams[N-1] substitution path that v6.1.1 wired up for the pgwire extended-query protocol).
SpgArguments
Buffer of bound arguments for one Execute call. Indexed 0..N; PG-style $1 resolves to slot 0.
SpgColumn
Per-column metadata in an SPG result set. mailrs’s #[derive(FromRow)] reads columns by name via Row::column which calls name() on this type.
SpgConnectOptions
Options for opening an SpgConnection.
SpgConnection
One sqlx connection backed by an in-process SPG.
SpgQueryResult
Rows-affected counter returned by every DML execute. SPG doesn’t have last-insert-id (BIGSERIAL is computed inside the engine + visible only via RETURNING); only the affected-count is surfaced here.
SpgRow
A single result row from an SPG-shape SELECT.
SpgStatement
Prepared-statement handle. Holds:
SpgTransactionManager
Wires Connection::begin / Transaction::commit / Transaction::rollback to engine-side BEGIN/COMMIT/ROLLBACK statements.
SpgTypeInfo
SPG column type info. Stores the concrete [Kind] so the adapter can drive PG-shape column metadata that #[derive(FromRow)] expects.
SpgValue
Owned form of an SPG cell as it comes back from a query. Wraps spg_embedded::Value + the column’s static SpgTypeInfo so the decode path can drive sqlx’s type- compatibility check (Decode::compatible).
SpgValueRef
Borrowed form of an SPG cell. Returned by SpgRow::try_get_raw to let Decode implementations read the value without taking ownership.

Enums§

EngineValue
A row-cell value, including SQL NULL. Float uses f64; NaN compares non-equal to itself (PG behaviour) — PartialEq is derived so callers must opt into NaN-aware comparison if they need stronger guarantees.

Traits§

SpgPoolExt
Convenience constructors that mirror sqlx’s pool-construction shape (PgPool::connect(url) style). Implemented as an extension trait on SpgPool so consumers can write SpgPool::connect_in_memory().await directly.

Type Aliases§

SpgPool
Drop-in replacement for sqlx::PgPool over an in-process SPG. Same Pool<Spg> shape — every sqlx-core API generic over Pool<DB> works against this alias.
SpgPoolOptions
Pool builder hooks — re-exported for ergonomic SpgPoolOptions::new() calls in mailrs-shape code.