Extract a Db::close method and remove deref to PgPool
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
co-authored by
Nathan Sobo
parent
0b9767651b
commit
b13da81a84
+13
-6
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user