@@ -47,16 +47,35 @@ func NewSharedUniqueInMemorySQLiteDatabase() (string, error) {
4747 return fmt .Sprintf ("sqlite://file:%s/db.sqlite?_fk=true&mode=memory&cache=shared" , dir ), nil
4848}
4949
50- // NewSQLiteTestDatabase creates a new unique SQLite database
50+ // NewSQLiteTestDatabase creates a new in-memory, unique SQLite database
5151// which is shared amongst all callers and identified by an individual file name.
5252func NewSQLiteTestDatabase (t interface {
5353 TempDir () string
5454}) string {
5555 return NewSQLiteInMemoryDatabase (t .TempDir ())
5656}
5757
58- // NewSQLiteInMemoryDatabase creates a new unique SQLite database
58+ // NewSQLiteInMemoryDatabase creates a new in-memory, unique SQLite database
5959// which is shared amongst all callers and identified by an individual file name.
6060func NewSQLiteInMemoryDatabase (name string ) string {
6161 return fmt .Sprintf ("sqlite://file:%s?_fk=true&mode=memory&cache=shared" , name )
6262}
63+
64+ // NewSQLiteDatabase creates a new on-disk, unique SQLite database
65+ // which is shared amongst all callers and identified by an individual file name.
66+ // This is sometimes necessary over a in-memory database, for example when multiple tests/goroutines run in parallel
67+ // and access the same table.
68+ // This would result in a locking error from SQLite when running in-memory.
69+ // Additionally, shared cache mode is deprecated and discouraged, and the problem is better solved with the WAL,
70+ // according to official docs.
71+ func NewSQLiteDatabase (name string ) string {
72+ return fmt .Sprintf ("sqlite://file:%s/test.db?_fk=true&_journal=WAL" , name )
73+ }
74+
75+ // NewSQLiteTestDatabaseOnDisk creates a new on-disk, unique SQLite database
76+ // which is shared amongst all callers and identified by an individual file name.
77+ func NewSQLiteTestDatabaseOnDisk (t interface {
78+ TempDir () string
79+ }) string {
80+ return NewSQLiteDatabase (t .TempDir ())
81+ }
0 commit comments