Extract a Db::close method and remove deref to PgPool

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Antonio Scandurra
2021-08-20 14:58:14 +02:00
co-authored by Nathan Sobo
parent 0b9767651b
commit b13da81a84
2 changed files with 16 additions and 23 deletions
+13 -6
View File
@@ -328,13 +328,20 @@ impl Db {
.fetch_all(&self.0)
.await
}
}
impl std::ops::Deref for Db {
type Target = sqlx::PgPool;
fn deref(&self) -> &Self::Target {
&self.0
#[cfg(test)]
pub async fn close(&self, db_name: &str) {
let query = "
SELECT pg_terminate_backend(pg_stat_activity.pid)
FROM pg_stat_activity
WHERE pg_stat_activity.datname = '{}' AND pid <> pg_backend_pid();
";
sqlx::query(query)
.bind(db_name)
.execute(&self.0)
.await
.unwrap();
self.0.close().await;
}
}