Browse Source

Remove macro, replaced with an function

Signed-off-by: BlackDex <black.dex@gmail.com>
pull/6279/head
BlackDex 3 weeks ago
parent
commit
02af16bb08
No known key found for this signature in database GPG Key ID: 58C80A2AA6C765E1
  1. 12
      Cargo.lock
  2. 2
      Cargo.toml
  3. 50
      src/db/mod.rs

12
Cargo.lock

@ -4726,9 +4726,9 @@ dependencies = [
[[package]]
name = "serde"
version = "1.0.225"
version = "1.0.226"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd6c24dee235d0da097043389623fb913daddf92c76e9f5a1db88607a0bcbd1d"
checksum = "0dca6411025b24b60bfa7ec1fe1f8e710ac09782dca409ee8237ba74b51295fd"
dependencies = [
"serde_core",
"serde_derive",
@ -4756,18 +4756,18 @@ dependencies = [
[[package]]
name = "serde_core"
version = "1.0.225"
version = "1.0.226"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "659356f9a0cb1e529b24c01e43ad2bdf520ec4ceaf83047b83ddcc2251f96383"
checksum = "ba2ba63999edb9dac981fb34b3e5c0d111a69b0924e253ed29d83f7c99e966a4"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.225"
version = "1.0.226"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ea936adf78b1f766949a4977b91d2f5595825bd6ec079aa9543ad2685fc4516"
checksum = "8db53ae22f34573731bafa1db20f04027b2d25e02d8205921b569171699cdb33"
dependencies = [
"proc-macro2",
"quote",

2
Cargo.toml

@ -80,7 +80,7 @@ tokio = { version = "1.47.1", features = ["rt-multi-thread", "fs", "io-util", "p
tokio-util = { version = "0.7.16", features = ["compat"]}
# A generic serialization/deserialization framework
serde = { version = "1.0.225", features = ["derive"] }
serde = { version = "1.0.226", features = ["derive"] }
serde_json = "1.0.145"
# A safe, extensible ORM and Query builder

50
src/db/mod.rs

@ -247,34 +247,38 @@ impl DbConnType {
}
}
#[macro_export]
macro_rules! db_run_base {
( $conn:ident ) => {
let conn = std::sync::Arc::clone(&$conn.conn);
impl DbConn {
pub async fn run<F, R>(&self, f: F) -> R
where
F: FnOnce(&mut DbConnInner) -> R + Send,
R: Send + 'static,
{
let conn = Arc::clone(&self.conn);
let mut conn = conn.lock_owned().await;
let $conn = conn.as_mut().expect("internal invariant broken: self.conn is Some");
};
let conn = conn.as_mut().expect("Internal invariant broken: self.conn is Some");
// Run blocking can't be used due to the 'static limitation, use block_in_place instead
tokio::task::block_in_place(move || f(conn))
}
}
#[macro_export]
macro_rules! db_run {
( $conn:ident: $body:block ) => {{
db_run_base!($conn);
// Run blocking can't be used due to the 'static limitation, use block_in_place instead
tokio::task::block_in_place(move || $body )
}};
( $conn:ident: $( $($db:ident),+ $body:block )+ ) => {{
db_run_base!($conn);
match std::ops::DerefMut::deref_mut($conn) {
$($(
#[cfg($db)]
pastey::paste!(&mut $crate::db::DbConnInner::[<$db:camel>](ref mut $conn)) => {
// Run blocking can't be used due to the 'static limitation, use block_in_place instead
tokio::task::block_in_place(move || $body )
},
)+)+}
}};
( $conn:ident: $body:block ) => {
$conn.run(move |$conn| $body).await
};
( $conn:ident: $( $($db:ident),+ $body:block )+ ) => {
$conn.run(move |$conn| {
match $conn {
$($(
#[cfg($db)]
pastey::paste!(&mut $crate::db::DbConnInner::[<$db:camel>](ref mut $conn)) => {
$body
},
)+)+}
}).await
};
}
pub mod schema;

Loading…
Cancel
Save