Close connection explicitly (#1236)
* Close connection and transaction * Close connection only
This commit is contained in:
parent
f65c931751
commit
115e19a95e
@ -283,6 +283,26 @@ impl DatabaseConnection {
|
|||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Explicitly close the database connection
|
||||||
|
pub async fn close(self) -> Result<(), DbErr> {
|
||||||
|
match self {
|
||||||
|
#[cfg(feature = "sqlx-mysql")]
|
||||||
|
DatabaseConnection::SqlxMySqlPoolConnection(conn) => conn.close().await,
|
||||||
|
#[cfg(feature = "sqlx-postgres")]
|
||||||
|
DatabaseConnection::SqlxPostgresPoolConnection(conn) => conn.close().await,
|
||||||
|
#[cfg(feature = "sqlx-sqlite")]
|
||||||
|
DatabaseConnection::SqlxSqlitePoolConnection(conn) => conn.close().await,
|
||||||
|
#[cfg(feature = "mock")]
|
||||||
|
DatabaseConnection::MockDatabaseConnection(_) => {
|
||||||
|
// Nothing to cleanup, we just consume the `DatabaseConnection`
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
DatabaseConnection::Disconnected => {
|
||||||
|
Err(DbErr::Conn(RuntimeErr::Internal("Disconnected".to_owned())))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DbBackend {
|
impl DbBackend {
|
||||||
|
@ -185,6 +185,11 @@ impl SqlxMySqlPoolConnection {
|
|||||||
{
|
{
|
||||||
self.metric_callback = Some(Arc::new(callback));
|
self.metric_callback = Some(Arc::new(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Explicitly close the MySQL connection
|
||||||
|
pub async fn close(self) -> Result<(), DbErr> {
|
||||||
|
Ok(self.pool.close().await)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<MySqlRow> for QueryResult {
|
impl From<MySqlRow> for QueryResult {
|
||||||
|
@ -200,6 +200,11 @@ impl SqlxPostgresPoolConnection {
|
|||||||
{
|
{
|
||||||
self.metric_callback = Some(Arc::new(callback));
|
self.metric_callback = Some(Arc::new(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Explicitly close the Postgres connection
|
||||||
|
pub async fn close(self) -> Result<(), DbErr> {
|
||||||
|
Ok(self.pool.close().await)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<PgRow> for QueryResult {
|
impl From<PgRow> for QueryResult {
|
||||||
|
@ -192,6 +192,11 @@ impl SqlxSqlitePoolConnection {
|
|||||||
{
|
{
|
||||||
self.metric_callback = Some(Arc::new(callback));
|
self.metric_callback = Some(Arc::new(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Explicitly close the SQLite connection
|
||||||
|
pub async fn close(self) -> Result<(), DbErr> {
|
||||||
|
Ok(self.pool.close().await)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<SqliteRow> for QueryResult {
|
impl From<SqliteRow> for QueryResult {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user