Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions oryx/dbal/dsn.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,35 @@ func NewSharedUniqueInMemorySQLiteDatabase() (string, error) {
return fmt.Sprintf("sqlite://file:%s/db.sqlite?_fk=true&mode=memory&cache=shared", dir), nil
}

// NewSQLiteTestDatabase creates a new unique SQLite database
// NewSQLiteTestDatabase creates a new in-memory, unique SQLite database
// which is shared amongst all callers and identified by an individual file name.
func NewSQLiteTestDatabase(t interface {
TempDir() string
}) string {
return NewSQLiteInMemoryDatabase(t.TempDir())
}

// NewSQLiteInMemoryDatabase creates a new unique SQLite database
// NewSQLiteInMemoryDatabase creates a new in-memory, unique SQLite database
// which is shared amongst all callers and identified by an individual file name.
func NewSQLiteInMemoryDatabase(name string) string {
return fmt.Sprintf("sqlite://file:%s?_fk=true&mode=memory&cache=shared", name)
}

// NewSQLiteDatabase creates a new on-disk, unique SQLite database
// which is shared amongst all callers and identified by an individual file name.
// This is sometimes necessary over a in-memory database, for example when multiple tests/goroutines run in parallel
// and access the same table.
// This would result in a locking error from SQLite when running in-memory.
// Additionally, shared cache mode is deprecated and discouraged, and the problem is better solved with the WAL,
// according to official docs.
func NewSQLiteDatabase(name string) string {
return fmt.Sprintf("sqlite://file:%s/test.db?_fk=true&_journal=WAL", name)
}

// NewSQLiteTestDatabaseOnDisk creates a new on-disk, unique SQLite database
// which is shared amongst all callers and identified by an individual file name.
func NewSQLiteTestDatabaseOnDisk(t interface {
TempDir() string
}) string {
return NewSQLiteDatabase(t.TempDir())
}