Skip to content

Commit b22d828

Browse files
authored
Merge pull request #408 from cschleiden/sqlite-params
Update sqlite DSN
2 parents d4b4b73 + d303de9 commit b22d828

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

backend/sqlite/sqlite.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func NewInMemoryBackend(opts ...option) *sqliteBackend {
5353
}
5454

5555
func NewSqliteBackend(path string, opts ...option) *sqliteBackend {
56-
return newSqliteBackend(fmt.Sprintf("file:%v?_mutex=no&_journal=wal", path), opts...)
56+
return newSqliteBackend(fmt.Sprintf("file:%v", path), opts...)
5757
}
5858

5959
func newSqliteBackend(dsn string, opts ...option) *sqliteBackend {
@@ -71,6 +71,15 @@ func newSqliteBackend(dsn string, opts ...option) *sqliteBackend {
7171
panic(err)
7272
}
7373

74+
// Set WAL mode via PRAGMA
75+
if _, err := db.Exec("PRAGMA journal_mode=WAL;"); err != nil {
76+
panic(err)
77+
}
78+
79+
if _, err = db.Exec("PRAGMA busy_timeout = 5000;"); err != nil {
80+
panic(err)
81+
}
82+
7483
// SQLite does not support multiple writers on the database, see https://www.sqlite.org/faq.html#q5
7584
// A frequently used workaround is to have a single connection, effectively acting as a mutex
7685
// See https://github.com/mattn/go-sqlite3/issues/274 for more context

0 commit comments

Comments
 (0)