pub mod user; pub mod error; pub mod schema; pub mod gamenight; pub mod gamenight_participants; pub mod game; pub mod owned_game; use diesel::r2d2::ConnectionManager; use diesel::r2d2::ManageConnection; use diesel::r2d2::Pool; use diesel::r2d2::PooledConnection; use diesel::PgConnection; use diesel_migrations::embed_migrations; use diesel_migrations::EmbeddedMigrations; use diesel_migrations::MigrationHarness; pub use user::login; pub use user::register; pub use gamenight::gamenights; pub use gamenight_participants::get_participants; pub use game::games; pub const MIGRATIONS: EmbeddedMigrations = embed_migrations!(); pub type DbConnection = PgConnection; pub type DbPool = Pool>; pub fn run_migration(conn: &mut DbConnection) { conn.run_pending_migrations(MIGRATIONS).unwrap(); } pub fn get_connection_pool(url: &str) -> DbPool { let manager = ConnectionManager::::new(url); // Refer to the `r2d2` documentation for more methods to use // when building a connection pool Pool::builder() .test_on_check_out(true) .build(manager) .expect("Could not build connection pool") } pub trait GetConnection where T: ManageConnection { fn get_conn(&self) -> PooledConnection; } impl GetConnection for Pool { fn get_conn(&self) -> PooledConnection { self.get().expect("Couldn't get db connection from pool") } }