Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions postgres_query/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ macro_rules! client_deref_impl {
T::prepare(self, sql).await
}

async fn prepare_static(&self, sql: &'static str) -> Result<Statement, SqlError> {
T::prepare_static(self, sql).await
}

async fn execute_raw<'a>(
&'a self,
statement: &Statement,
Expand Down
15 changes: 12 additions & 3 deletions postgres_query/src/client/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ where
}
}

/// Wrap new client with an existing cache.
pub fn map_clone<U: GenericClient>(&self, client: U) -> Caching<U> {
Caching {
client,
cache: self.cache.clone(),
}
}

/// Return the inner client.
pub fn into_inner(self) -> C {
self.client
Expand Down Expand Up @@ -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<Caching<$transaction>, 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 })
}
}
};
Expand Down