1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//! Shared test fixture: in-memory SQLite + scratch table with a REAL UNIQUE INDEX
//! for `ConstraintMap` integration tests.
//!
//! The `cw` scratch table has a NON-PK UNIQUE INDEX on `slug` so a duplicate INSERT
//! raises `SQLITE_CONSTRAINT_UNIQUE` (error code 2067), whose driver message is:
//! `"UNIQUE constraint failed: cw.slug"` — the `table.column` token the SQLite path
//! of `ConstraintMap::try_map` parses.
//!
//! Tests using this fixture MUST be annotated `#[serial]` (from the `serial_test`
//! crate) because `DB` is a process-global singleton. Concurrent tests would race
//! on initialization and on the shared `cw` table.
//!
//! # Usage
//!
//! ```rust,ignore
//! mod constraint_map_fixture;
//! use constraint_map_fixture::{exec_sql, init_constraint_db};
//!
//! #[tokio::test]
//! #[serial]
//! async fn my_test() {
//! init_constraint_db().await;
//! exec_sql("INSERT INTO cw (id, slug) VALUES (1, 'hello')").await.expect("seed");
//! let err = exec_sql("INSERT INTO cw (id, slug) VALUES (2, 'hello')").await
//! .expect_err("expected UNIQUE violation");
//! // feed err to ConstraintMap::try_map ...
//! }
//! ```
use ;
use ;
/// Initialize an in-memory SQLite DB singleton and create a `cw` scratch table
/// with a NON-PK UNIQUE INDEX on `slug`. Safe to call repeatedly within a
/// `#[serial]` test suite — `CREATE TABLE IF NOT EXISTS` and `CREATE UNIQUE INDEX
/// IF NOT EXISTS` are idempotent.
///
/// After this returns, `DB::connection()` yields a live SQLite connection and any
/// attempt to insert a duplicate `slug` value will raise a real UNIQUE-constraint
/// violation (`SQLITE_CONSTRAINT_UNIQUE`, code 2067).
pub async
/// Execute a raw SQL statement against the singleton connection. Returns
/// `Err(DbErr)` on any DB error — including a UNIQUE-constraint violation — so
/// callers can capture and feed the error to `ConstraintMap::try_map`.
///
/// Callers must have called [`init_constraint_db`] first.
pub async