mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-08-06 21:44:49 -04:00
fix(asb): Allow history command to be run while asb is running (#1724)
Co-authored-by: einliterflasche <einliterflasche@pm.me>
This commit is contained in:
parent
ef49b471d8
commit
c80bdb2d8c
6 changed files with 55 additions and 18 deletions
|
@ -83,16 +83,25 @@ impl Swap {
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn open_db(sqlite_path: impl AsRef<Path>) -> Result<Arc<dyn Database + Send + Sync>> {
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, Hash, PartialEq)]
|
||||
pub enum AccessMode {
|
||||
ReadWrite,
|
||||
ReadOnly,
|
||||
}
|
||||
|
||||
pub async fn open_db(
|
||||
sqlite_path: impl AsRef<Path>,
|
||||
access_mode: AccessMode,
|
||||
) -> Result<Arc<dyn Database + Send + Sync>> {
|
||||
if sqlite_path.as_ref().exists() {
|
||||
tracing::debug!("Using existing sqlite database.");
|
||||
let sqlite = SqliteDatabase::open(sqlite_path).await?;
|
||||
let sqlite = SqliteDatabase::open(sqlite_path, access_mode).await?;
|
||||
Ok(Arc::new(sqlite))
|
||||
} else {
|
||||
tracing::debug!("Creating and using new sqlite database.");
|
||||
ensure_directory_exists(sqlite_path.as_ref())?;
|
||||
tokio::fs::File::create(&sqlite_path).await?;
|
||||
let sqlite = SqliteDatabase::open(sqlite_path).await?;
|
||||
let sqlite = SqliteDatabase::open(sqlite_path, access_mode).await?;
|
||||
Ok(Arc::new(sqlite))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue