chore: open private conn field
This commit is contained in:
parent
7f93215926
commit
5e50da32e8
3 changed files with 28 additions and 7 deletions
|
@ -11,6 +11,13 @@ pub struct Client {
|
||||||
migrations_table_name: String,
|
migrations_table_name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Client {
|
||||||
|
#[must_use]
|
||||||
|
pub fn conn(&self) -> &PooledConn {
|
||||||
|
&self.conn
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl OpenDatabaseConnection for Client {
|
impl OpenDatabaseConnection for Client {
|
||||||
fn manual(connection_string: &str, migrations_table_name: &str) -> MigraResult<Self> {
|
fn manual(connection_string: &str, migrations_table_name: &str) -> MigraResult<Self> {
|
||||||
let conn = Pool::new_manual(1, 1, connection_string)
|
let conn = Pool::new_manual(1, 1, connection_string)
|
||||||
|
|
|
@ -6,10 +6,17 @@ use postgres::{Client as PostgresClient, NoTls};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
pub struct Client {
|
pub struct Client {
|
||||||
client: PostgresClient,
|
conn: PostgresClient,
|
||||||
migrations_table_name: String,
|
migrations_table_name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Client {
|
||||||
|
#[must_use]
|
||||||
|
pub fn conn(&self) -> &PostgresClient {
|
||||||
|
&self.conn
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl fmt::Debug for Client {
|
impl fmt::Debug for Client {
|
||||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
fmt.debug_struct("Client")
|
fmt.debug_struct("Client")
|
||||||
|
@ -20,10 +27,10 @@ impl fmt::Debug for Client {
|
||||||
|
|
||||||
impl OpenDatabaseConnection for Client {
|
impl OpenDatabaseConnection for Client {
|
||||||
fn manual(connection_string: &str, migrations_table_name: &str) -> MigraResult<Self> {
|
fn manual(connection_string: &str, migrations_table_name: &str) -> MigraResult<Self> {
|
||||||
let client = PostgresClient::connect(connection_string, NoTls)
|
let conn = PostgresClient::connect(connection_string, NoTls)
|
||||||
.map_err(|err| Error::db(err.into(), DbKind::DatabaseConnection))?;
|
.map_err(|err| Error::db(err.into(), DbKind::DatabaseConnection))?;
|
||||||
Ok(Client {
|
Ok(Client {
|
||||||
client,
|
conn,
|
||||||
migrations_table_name: migrations_table_name.to_owned(),
|
migrations_table_name: migrations_table_name.to_owned(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -31,7 +38,7 @@ impl OpenDatabaseConnection for Client {
|
||||||
|
|
||||||
impl BatchExecute for Client {
|
impl BatchExecute for Client {
|
||||||
fn batch_execute(&mut self, sql: &str) -> StdResult<()> {
|
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.migrations_table_name
|
||||||
);
|
);
|
||||||
|
|
||||||
self.client
|
self.conn
|
||||||
.execute(stmt.as_str(), &[&name])
|
.execute(stmt.as_str(), &[&name])
|
||||||
.map_err(|err| Error::db(err.into(), DbKind::InsertMigration))
|
.map_err(|err| Error::db(err.into(), DbKind::InsertMigration))
|
||||||
}
|
}
|
||||||
|
@ -68,7 +75,7 @@ impl ManageMigrations for Client {
|
||||||
&self.migrations_table_name
|
&self.migrations_table_name
|
||||||
);
|
);
|
||||||
|
|
||||||
self.client
|
self.conn
|
||||||
.execute(stmt.as_str(), &[&name])
|
.execute(stmt.as_str(), &[&name])
|
||||||
.map_err(|err| Error::db(err.into(), DbKind::DeleteMigration))
|
.map_err(|err| Error::db(err.into(), DbKind::DeleteMigration))
|
||||||
}
|
}
|
||||||
|
@ -79,7 +86,7 @@ impl ManageMigrations for Client {
|
||||||
&self.migrations_table_name
|
&self.migrations_table_name
|
||||||
);
|
);
|
||||||
|
|
||||||
self.client
|
self.conn
|
||||||
.query(stmt.as_str(), &[])
|
.query(stmt.as_str(), &[])
|
||||||
.and_then(|res| {
|
.and_then(|res| {
|
||||||
res.into_iter()
|
res.into_iter()
|
||||||
|
|
|
@ -10,6 +10,13 @@ pub struct Client {
|
||||||
migrations_table_name: String,
|
migrations_table_name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Client {
|
||||||
|
#[must_use]
|
||||||
|
pub fn conn(&self) -> &Connection {
|
||||||
|
&self.conn
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl OpenDatabaseConnection for Client {
|
impl OpenDatabaseConnection for Client {
|
||||||
fn manual(connection_string: &str, migrations_table_name: &str) -> MigraResult<Self> {
|
fn manual(connection_string: &str, migrations_table_name: &str) -> MigraResult<Self> {
|
||||||
let conn = Connection::open(connection_string)
|
let conn = Connection::open(connection_string)
|
||||||
|
|
Reference in a new issue