Skip to content

Added prepared_static for &GenericClient #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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