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
//! Database test helpers — always roll back so tests never mutate state.
use crate;
use Future;
use Pin;
/// Run `f` inside a transaction that is **always rolled back**, regardless of
/// the closure's result. Lets a test exercise real queries against a real
/// database without persisting any changes.
///
/// The closure receives `&mut Transaction` and returns a boxed future — mirror
/// sqlx's own [`Pool::transaction`] shape: `|tx| Box::pin(async move { … })`.
///
/// Available when the `sqlx` feature (via any `sqlx-*` backend) is enabled.
///
/// ```no_run
/// # #[cfg(feature = "sqlx-sqlite")]
/// # async fn demo() -> ultimo::Result<()> {
/// use ultimo::testing::with_test_transaction;
/// let pool = sqlx::SqlitePool::connect("sqlite::memory:").await.unwrap();
/// with_test_transaction(&pool, |tx| {
/// Box::pin(async move {
/// sqlx::query("INSERT INTO t (id) VALUES (1)")
/// .execute(&mut **tx)
/// .await
/// .unwrap();
/// Ok(())
/// })
/// })
/// .await?; // the insert is rolled back here
/// # Ok(())
/// # }
/// ```
pub async