Using prepare_cached
#343
Answered
by
bikeshedder
Zerowalker
asked this question in
Q&A
-
I got a wrapper for the client and is wondering if using #[derive(Clone)]
pub struct Db {
pool: Pool,
}
impl Db {
pub fn from(pool: Pool) -> Self {
Db { pool }
}
async fn query_one(
&self,
statement: &str,
params: &[&(dyn ToSql + Sync)],
) -> Result<Row, DbError> {
let client = self.pool.get().await?;
let stmt = client.prepare_cached(statement).await?;
Ok(client.query_one(&stmt, params).await?)
}
} As there are limited hardcoded queries with just the parameters changing, |
Beta Was this translation helpful? Give feedback.
Answered by
bikeshedder
Aug 7, 2024
Replies: 1 comment 1 reply
-
Sorry for the slow response. "Discussion" in GitHub doesn't show a unread counter and I miss new messages easily. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
bikeshedder
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
prepare_cached
should only be used for non-dynamic queries. So this is exactly what you're looking for. 👍Sorry for the slow response. "Discussion" in GitHub doesn't show a unread counter and I miss new messages easily.