Skip to content

Commit b72915c

Browse files
authored
Merge pull request #5905 from nymtech/am/sqlx-guard-obtain-db-path-from-pool
sqlx-pool-guard: obtain filename from connect options
2 parents 8f6f696 + add3e86 commit b72915c

File tree

3 files changed

+11
-8
lines changed
  • common
    • client-core/surb-storage/src/backend/fs_backend
    • credential-storage/src/persistent_storage
  • sqlx-pool-guard/src

3 files changed

+11
-8
lines changed

common/client-core/surb-storage/src/backend/fs_backend/manager.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl StorageManager {
3737
.journal_mode(sqlx::sqlite::SqliteJournalMode::Wal)
3838
.synchronous(SqliteSynchronous::Normal)
3939
.auto_vacuum(SqliteAutoVacuum::Incremental)
40-
.filename(&database_path)
40+
.filename(database_path)
4141
.create_if_missing(fresh)
4242
.disable_statement_logging();
4343

@@ -49,8 +49,7 @@ impl StorageManager {
4949
}
5050
};
5151

52-
let connection_pool =
53-
SqlitePoolGuard::new(database_path.as_ref().to_path_buf(), connection_pool);
52+
let connection_pool = SqlitePoolGuard::new(connection_pool);
5453

5554
if let Err(err) = sqlx::migrate!("./fs_surbs_migrations")
5655
.run(&*connection_pool)

common/credential-storage/src/persistent_storage/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl PersistentStorage {
6363
.journal_mode(sqlx::sqlite::SqliteJournalMode::Wal)
6464
.synchronous(SqliteSynchronous::Normal)
6565
.auto_vacuum(SqliteAutoVacuum::Incremental)
66-
.filename(&database_path)
66+
.filename(database_path)
6767
.create_if_missing(true)
6868
.disable_statement_logging();
6969

@@ -75,8 +75,7 @@ impl PersistentStorage {
7575
}
7676
};
7777

78-
let connection_pool =
79-
SqlitePoolGuard::new(database_path.as_ref().to_path_buf(), connection_pool);
78+
let connection_pool = SqlitePoolGuard::new(connection_pool);
8079

8180
if let Err(err) = sqlx::migrate!("./migrations").run(&*connection_pool).await {
8281
error!("Failed to perform migration on the SQLx database: {err}");

sqlx-pool-guard/src/lib.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@ pub struct SqlitePoolGuard {
3939

4040
impl SqlitePoolGuard {
4141
/// Create new instance providing path to database and connection pool
42-
pub fn new(database_path: PathBuf, connection_pool: sqlx::SqlitePool) -> Self {
42+
pub fn new(connection_pool: sqlx::SqlitePool) -> Self {
43+
let database_path = connection_pool
44+
.connect_options()
45+
.get_filename()
46+
.to_path_buf();
47+
4348
Self {
4449
database_path,
4550
connection_pool,
@@ -160,7 +165,7 @@ mod tests {
160165
.await
161166
.unwrap();
162167

163-
let guard = SqlitePoolGuard::new(database_path.clone(), connection_pool);
168+
let guard = SqlitePoolGuard::new(connection_pool);
164169
assert!(
165170
guard
166171
.wait_for_db_files_close()

0 commit comments

Comments
 (0)