Specify WAL when opening the sqlite file to defend against deadlocks

This commit is contained in:
David Dworken 2022-11-12 06:39:37 -08:00
parent 6e7822ebae
commit e3a793c753
No known key found for this signature in database

View File

@ -86,8 +86,9 @@ func OpenLocalSqliteDb() (*gorm.DB, error) {
Colorful: false,
},
)
// TODO: should I specify WAL here: https://stackoverflow.com/questions/57118674/go-sqlite3-with-journal-mode-wal-gives-database-is-locked-error
db, err := gorm.Open(sqlite.Open(path.Join(homedir, data.HISHTORY_PATH, data.DB_PATH)), &gorm.Config{SkipDefaultTransaction: true, Logger: newLogger})
dbFilePath := path.Join(homedir, data.HISHTORY_PATH, data.DB_PATH)
dsn := fmt.Sprintf("file:%s?cache=shared&mode=rwc&_journal_mode=WAL", dbFilePath)
db, err := gorm.Open(sqlite.Open(dsn), &gorm.Config{SkipDefaultTransaction: true, Logger: newLogger})
if err != nil {
return nil, fmt.Errorf("failed to connect to the DB: %v", err)
}