diff --git a/migra/src/clients/mysql.rs b/migra/src/clients/mysql.rs index 5294e8e..f3c9105 100644 --- a/migra/src/clients/mysql.rs +++ b/migra/src/clients/mysql.rs @@ -11,6 +11,13 @@ pub struct Client { migrations_table_name: String, } +impl Client { + #[must_use] + pub fn conn(&self) -> &PooledConn { + &self.conn + } +} + impl OpenDatabaseConnection for Client { fn manual(connection_string: &str, migrations_table_name: &str) -> MigraResult { let conn = Pool::new_manual(1, 1, connection_string) diff --git a/migra/src/clients/postgres.rs b/migra/src/clients/postgres.rs index 898c49c..ae9f49b 100644 --- a/migra/src/clients/postgres.rs +++ b/migra/src/clients/postgres.rs @@ -6,10 +6,17 @@ use postgres::{Client as PostgresClient, NoTls}; use std::fmt; pub struct Client { - client: PostgresClient, + conn: PostgresClient, migrations_table_name: String, } +impl Client { + #[must_use] + pub fn conn(&self) -> &PostgresClient { + &self.conn + } +} + impl fmt::Debug for Client { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { fmt.debug_struct("Client") @@ -20,10 +27,10 @@ impl fmt::Debug for Client { impl OpenDatabaseConnection for Client { fn manual(connection_string: &str, migrations_table_name: &str) -> MigraResult { - let client = PostgresClient::connect(connection_string, NoTls) + let conn = PostgresClient::connect(connection_string, NoTls) .map_err(|err| Error::db(err.into(), DbKind::DatabaseConnection))?; Ok(Client { - client, + conn, migrations_table_name: migrations_table_name.to_owned(), }) } @@ -31,7 +38,7 @@ impl OpenDatabaseConnection for Client { impl BatchExecute for Client { fn batch_execute(&mut self, sql: &str) -> StdResult<()> { - self.client.batch_execute(sql).map_err(From::from) + self.conn.batch_execute(sql).map_err(From::from) } } @@ -57,7 +64,7 @@ impl ManageMigrations for Client { &self.migrations_table_name ); - self.client + self.conn .execute(stmt.as_str(), &[&name]) .map_err(|err| Error::db(err.into(), DbKind::InsertMigration)) } @@ -68,7 +75,7 @@ impl ManageMigrations for Client { &self.migrations_table_name ); - self.client + self.conn .execute(stmt.as_str(), &[&name]) .map_err(|err| Error::db(err.into(), DbKind::DeleteMigration)) } @@ -79,7 +86,7 @@ impl ManageMigrations for Client { &self.migrations_table_name ); - self.client + self.conn .query(stmt.as_str(), &[]) .and_then(|res| { res.into_iter() diff --git a/migra/src/clients/sqlite.rs b/migra/src/clients/sqlite.rs index bc055d8..d4a1d5b 100644 --- a/migra/src/clients/sqlite.rs +++ b/migra/src/clients/sqlite.rs @@ -10,6 +10,13 @@ pub struct Client { migrations_table_name: String, } +impl Client { + #[must_use] + pub fn conn(&self) -> &Connection { + &self.conn + } +} + impl OpenDatabaseConnection for Client { fn manual(connection_string: &str, migrations_table_name: &str) -> MigraResult { let conn = Connection::open(connection_string)