diff --git a/postgres_query/src/client.rs b/postgres_query/src/client.rs index 28ffd5f..7ac892b 100644 --- a/postgres_query/src/client.rs +++ b/postgres_query/src/client.rs @@ -145,6 +145,10 @@ macro_rules! client_deref_impl { T::prepare(self, sql).await } + async fn prepare_static(&self, sql: &'static str) -> Result { + T::prepare_static(self, sql).await + } + async fn execute_raw<'a>( &'a self, statement: &Statement, diff --git a/postgres_query/src/client/cache.rs b/postgres_query/src/client/cache.rs index 8aae80c..448b750 100644 --- a/postgres_query/src/client/cache.rs +++ b/postgres_query/src/client/cache.rs @@ -65,6 +65,14 @@ where } } + /// Wrap new client with an existing cache. + pub fn map_clone(&self, client: U) -> Caching { + Caching { + client, + cache: self.cache.clone(), + } + } + /// Return the inner client. pub fn into_inner(self) -> C { self.client @@ -213,10 +221,11 @@ macro_rules! impl_cached_transaction { impl Caching<$client> { /// Start a new transaction that shares the same cache as the current client. pub async fn transaction(&mut self) -> Result, Error> { - <$client>::transaction(self) + let cache = self.cache.clone(); + let tx = <$client>::transaction(self) .await - .map(Caching::new) - .map_err(Error::BeginTransaction) + .map_err(Error::BeginTransaction)?; + Ok(Caching { client: tx, cache }) } } };