Expose database path

This commit is contained in:
Andrej Mihajlov
2025-06-03 14:49:35 +02:00
committed by Bogdan-Ștefan Neacşu
parent a5d2ca139b
commit 6c58ea8f7c
+19 -14
View File
@@ -37,21 +37,8 @@ pub struct SqlitePoolGuard {
connection_pool: sqlx::SqlitePool,
}
impl Deref for SqlitePoolGuard {
type Target = sqlx::SqlitePool;
fn deref(&self) -> &Self::Target {
&self.connection_pool
}
}
impl DerefMut for SqlitePoolGuard {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.connection_pool
}
}
impl SqlitePoolGuard {
/// Create new instance providing path to database and connection pool
pub fn new(database_path: PathBuf, connection_pool: sqlx::SqlitePool) -> Self {
Self {
database_path,
@@ -59,6 +46,11 @@ impl SqlitePoolGuard {
}
}
/// Returns database path
pub fn database_path(&self) -> &Path {
&self.database_path
}
/// Close udnerlying sqlite pool and wait for files to be closed before returning.
pub async fn close(&self) {
// Avoid waiting for db files once the pool is marked closed to ensure that we don't wait on some other sqlite pool to close the database.
@@ -125,6 +117,19 @@ impl SqlitePoolGuard {
}
}
impl Deref for SqlitePoolGuard {
type Target = sqlx::SqlitePool;
fn deref(&self) -> &Self::Target {
&self.connection_pool
}
}
impl DerefMut for SqlitePoolGuard {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.connection_pool
}
}
#[cfg(test)]
mod tests {
use sqlx::{