Files
YANPM/apps/api/src/helpers/database.rs
2025-12-07 21:35:10 +08:00

14 lines
341 B
Rust

#[macro_export]
macro_rules! with_conn {
// Usage: with_conn!(&connection, tx_option, ident, |conn|-> { ... })
($conn:expr, $tx:expr, $ident:ident, $body:block) => {{
if let Some(t) = &$tx {
let $ident = t;
$body
} else {
let $ident = &$conn;
$body
}
}};
}