fix(electron): enable WAL mode for sqlite (#8336)

fix AF-1015
This commit is contained in:
pengx17
2024-09-25 04:06:03 +00:00
parent e6feb17ac7
commit e839947dd5
6 changed files with 36 additions and 3 deletions

View File

@@ -53,7 +53,7 @@ impl SqliteConnection {
let sqlite_options = SqliteConnectOptions::new()
.filename(&path)
.foreign_keys(false)
.journal_mode(sqlx::sqlite::SqliteJournalMode::Off);
.journal_mode(sqlx::sqlite::SqliteJournalMode::Wal);
let pool = SqlitePoolOptions::new()
.max_connections(4)
.connect_lazy_with(sqlite_options);
@@ -490,6 +490,19 @@ impl SqliteConnection {
}
}
/**
* Flush the WAL file to the database file.
* See https://www.sqlite.org/pragma.html#pragma_wal_checkpoint:~:text=PRAGMA%20schema.wal_checkpoint%3B
*/
#[napi]
pub async fn checkpoint(&self) -> napi::Result<()> {
sqlx::query("PRAGMA wal_checkpoint(FULL);")
.execute(&self.pool)
.await
.map_err(anyhow::Error::from)?;
Ok(())
}
pub async fn migrate_add_doc_id_index(&self) -> napi::Result<()> {
// ignore errors
match sqlx::query("CREATE INDEX IF NOT EXISTS idx_doc_id ON updates(doc_id);")