Added macro for handling both transaction and pooled connection
This commit is contained in:
13
apps/api/src/helpers/database.rs
Normal file
13
apps/api/src/helpers/database.rs
Normal file
@@ -0,0 +1,13 @@
|
||||
#[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
|
||||
}
|
||||
}};
|
||||
}
|
||||
Reference in New Issue
Block a user