Skip to content

Instantly share code, notes, and snippets.

@FrancisMurillo
Created February 8, 2023 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FrancisMurillo/1b5fc6318d2850a7c1bd2a4d1294c7d6 to your computer and use it in GitHub Desktop.
Save FrancisMurillo/1b5fc6318d2850a7c1bd2a4d1294c7d6 to your computer and use it in GitHub Desktop.
Carabao Dev - Start transaction on r2d2 connection checkout
use diesel::{
pg::PgConnection,
r2d2::{ConnectionManager, Error as DieselPoolError},
result::ConnectionError,
};
use r2d2::{CustomizeConnection, Pool};
#[derive(Debug)]
struct TestConnection;
impl CustomizeConnection<PgConnection, DieselPoolError> for TestConnection {
fn on_acquire(&self, conn: &mut PgConnection) -> Result<(), DieselPoolError> {
conn.begin_test_transaction().map_err(|err| {
DieselPoolError::ConnectionError(ConnectionError::CouldntSetupConfiguration(err))
})?;
Ok(())
}
fn on_release(&self, _conn: PgConnection) {}
}
fn main() {
let manager = ConnectionManager::<PgConnection>::new("MYPOSTGRESURL");
Pool::builder()
.max_size(*pool_size as u32)
.build(manager)
.unwrap();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment