Added macro for handling both transaction and pooled connection

This commit is contained in:
GW_MC
2025-12-07 19:09:37 +08:00
parent e758452509
commit 30e500ec44
3 changed files with 15 additions and 0 deletions

1
apps/api/src/helpers.rs Normal file
View File

@@ -0,0 +1 @@
pub mod database;

View 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
}
}};
}

View File

@@ -1,6 +1,7 @@
mod cmd;
mod configs;
mod errors;
mod helpers;
mod log;
mod middlewares;
mod routes;