spg_sqlx/database.rs
1//! v7.16.0 — the [`Spg`] marker type. Defines the 11 associated
2//! types `sqlx::Database` requires for the adapter to plug into
3//! every sqlx-core generic API (`query`, `query_as`, pool +
4//! transaction lifecycle).
5
6use sqlx_core::database::{Database, HasStatementCache};
7
8use crate::{
9 SpgArgumentValue, SpgArguments, SpgColumn, SpgConnection, SpgQueryResult, SpgRow, SpgStatement,
10 SpgTransactionManager, SpgTypeInfo, SpgValue, SpgValueRef,
11};
12
13/// sqlx 0.8 driver for spg-embedded.
14///
15/// Used as the `<DB>` type parameter on every sqlx-core generic
16/// API — e.g. `sqlx::query::<Spg>` is what
17/// `sqlx::query("...").execute(&spg_pool)` collapses to.
18///
19/// Single-database — the adapter wraps one in-process
20/// `AsyncDatabase` per [`SpgPool`][crate::SpgPool], with the
21/// `Mutex` inside `AsyncDatabase` providing the serialised
22/// engine-write invariant the spg-engine layer requires.
23#[derive(Debug)]
24pub struct Spg;
25
26impl Database for Spg {
27 type Connection = SpgConnection;
28 type TransactionManager = SpgTransactionManager;
29 type Row = SpgRow;
30 type QueryResult = SpgQueryResult;
31 type Column = SpgColumn;
32 type TypeInfo = SpgTypeInfo;
33 type Value = SpgValue;
34 type ValueRef<'r> = SpgValueRef<'r>;
35 type Arguments<'q> = SpgArguments<'q>;
36 type ArgumentBuffer<'q> = Vec<SpgArgumentValue<'q>>;
37 type Statement<'q> = SpgStatement<'q>;
38
39 const NAME: &'static str = "SPG";
40 const URL_SCHEMES: &'static [&'static str] = &["spg"];
41}
42
43// v7.16.0 — the engine plan cache lives inside spg-engine and
44// is shared by every connection clone. Mark the driver so
45// sqlx's prepared-statement reuse path opts in.
46impl HasStatementCache for Spg {}