Created
February 8, 2023 13:54
-
-
Save FrancisMurillo/1b5fc6318d2850a7c1bd2a4d1294c7d6 to your computer and use it in GitHub Desktop.
Carabao Dev - Start transaction on r2d2 connection checkout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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