Function hyper_scripter::db::get_file
source · pub fn get_file() -> PathBufExamples found in repository?
src/db.rs (line 15)
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
pub async fn get_pool(need_journal: &mut bool) -> Result<(SqlitePool, bool)> {
let file = get_file();
if !file.exists() {
*need_journal = true;
let pool = crate::migration::do_migrate(file).await?;
return Ok((pool, true));
}
let mut opt = SqliteConnectOptions::new().filename(&file);
if !*need_journal {
opt = opt.journal_mode(SqliteJournalMode::Off);
}
let res = SqlitePool::connect_with(opt).await;
let pool = match res {
Err(err) => {
// 通常是有其它程序用 journal mode 鎖住資料庫,例如正在編輯另一個腳本
log::warn!("資料庫錯誤 {},嘗試用 journal 再開一次", err);
*need_journal = true;
let opt = SqliteConnectOptions::new().filename(&file);
SqlitePool::connect_with(opt).await?
}
Ok(pool) => pool,
};
Ok((pool, false))
}