diff --git a/src/connector.rs b/src/connector.rs index efb296273..16419e412 100644 --- a/src/connector.rs +++ b/src/connector.rs @@ -12,8 +12,6 @@ mod queryable; mod result_set; mod transaction; -mod dbio; - #[cfg(feature = "mysql")] pub(crate) mod mysql; #[cfg(feature = "postgresql")] @@ -33,6 +31,5 @@ pub use connection_info::*; pub(crate) mod metrics; pub use self::result_set::*; -pub use dbio::DBIO; pub use queryable::*; pub use transaction::*; diff --git a/src/connector/dbio.rs b/src/connector/dbio.rs deleted file mode 100644 index 98cce079f..000000000 --- a/src/connector/dbio.rs +++ /dev/null @@ -1,28 +0,0 @@ -use futures::future::{BoxFuture, FutureExt}; -use std::{ - future::Future, - pin::Pin, - task::{Context, Poll}, -}; - -/// The main unit of asynchronous IO. For now just a shell for a boxed `Future`, -/// allowing access to the metrics and logging of IO. -#[must_use] -pub struct DBIO<'a, T>(BoxFuture<'a, crate::Result>); - -impl<'a, T> DBIO<'a, T> { - pub fn new(inner: F) -> Self - where - F: Future> + Send + 'a, - { - Self(inner.boxed()) - } -} - -impl<'a, T> Future for DBIO<'a, T> { - type Output = crate::Result; - - fn poll(mut self: Pin<&mut Self>, ctx: &mut Context<'_>) -> Poll { - self.0.as_mut().poll(ctx) - } -} diff --git a/src/connector/metrics.rs b/src/connector/metrics.rs index 6d9436322..934b8e405 100644 --- a/src/connector/metrics.rs +++ b/src/connector/metrics.rs @@ -1,42 +1,42 @@ -use crate::{ - ast::{Params, Value}, - connector::DBIO, -}; +use crate::ast::{Params, Value}; use std::{future::Future, time::Instant}; -pub(crate) fn query<'a, F, T, U>(tag: &'static str, query: &'a str, params: &'a [Value], f: F) -> DBIO<'a, T> +pub(crate) async fn query<'a, F, T, U>( + tag: &'static str, + query: &'a str, + params: &'a [Value<'_>], + f: F, +) -> crate::Result where F: FnOnce() -> U + Send + 'a, U: Future> + Send, { - DBIO::new(async move { - let start = Instant::now(); - let res = f().await; - let end = Instant::now(); + let start = Instant::now(); + let res = f().await; + let end = Instant::now(); - if *crate::LOG_QUERIES { - #[cfg(not(feature = "tracing-log"))] - { - info!( - "query: \"{}\", params: {} (in {}ms)", - query, - Params(params), - start.elapsed().as_millis(), - ); - } - #[cfg(feature = "tracing-log")] - { - tracing::info!( - query, - item_type = "query", - params = %Params(params), - duration_ms = start.elapsed().as_millis() as u64, - ) - } + if *crate::LOG_QUERIES { + #[cfg(not(feature = "tracing-log"))] + { + info!( + "query: \"{}\", params: {} (in {}ms)", + query, + Params(params), + start.elapsed().as_millis(), + ); } + #[cfg(feature = "tracing-log")] + { + tracing::info!( + query, + item_type = "query", + params = %Params(params), + duration_ms = start.elapsed().as_millis() as u64, + ) + } + } - timing!(format!("{}.query.time", tag), start, end); + timing!(format!("{}.query.time", tag), start, end); - res - }) + res } diff --git a/src/prelude.rs b/src/prelude.rs index bf516f6d9..b3e35611e 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -2,6 +2,6 @@ pub use crate::ast::*; #[cfg(any(feature = "sqlite", feature = "mysql", feature = "postgresql"))] pub use crate::connector::{ - ConnectionInfo, Queryable, ResultRow, ResultSet, SqlFamily, Transaction, TransactionCapable, DBIO, + ConnectionInfo, Queryable, ResultRow, ResultSet, SqlFamily, Transaction, TransactionCapable, }; pub use crate::{col, val, values};