How to store and use values made during on_acquire?
mu-arch opened this issue · 2 comments
mu-arch commented
I have the following code:
#[derive(Debug)]
struct ConnectionCustomizer {}
#[async_trait]
impl bb8_postgres::bb8::CustomizeConnection<Client, bb8_postgres::tokio_postgres::Error> for ConnectionCustomizer {
async fn on_acquire(
&self,
connection: & mut bb8_postgres::tokio_postgres::Client,
) -> Result<(), bb8_postgres::tokio_postgres::Error> {
println!("test");
Ok(())
}
}
I want to prepare a number of queries using this for every connection. However, I'm struggling to think of a way to actually get the reference to the prepared statements for a specific connection. Is there a way to bind some data to the connection object, or at least a way to get some unique identifier for a connection that I could use to lookup their prepared statements in a hash table?
djc commented
Maybe you should write your own ManageConnection
instead of using bb8-postgres, which can deal with a type that is wrapped around tokio_postgres::Client
(and potentially Deref
s to it)?
djc commented
(If it's generic enough I'd be happy to accept it into bb8-postgres and maintain it.)