Skip to main content

alibi_sqlx/
hooks.rs

1//! `SQLx` bindings for the shared database lifecycle hooks.
2
3use crate::pool::{SqlxPool, SqlxTransaction};
4pub use alibi_core::hooks::current_request_hook_context;
5pub use alibi_core::store::{DatabaseHookContext, DatabaseHooks, HookBackend, HookControl};
6
7/// The `SQLx` hook backend: implement [`DatabaseHooks<S, SqlxBackend>`] to
8/// receive its pool and transaction.
9///
10/// Transactional creation after callbacks retain the created snapshots and
11/// run in operation order after commit. Rollback discards them; callback errors
12/// are returned to the caller after the auth writes have committed.
13#[derive(Debug, Clone, Copy)]
14pub struct SqlxBackend;
15
16impl HookBackend for SqlxBackend {
17    type Connection = SqlxPool;
18    type Transaction = SqlxTransaction;
19}
20
21/// Context passed to `SQLx` lifecycle hooks.
22pub type SqlxHookContext<'a> = DatabaseHookContext<'a, SqlxBackend>;