Skip to content

Commit

Permalink
Allow multiple instances in memory
Browse files Browse the repository at this point in the history
  • Loading branch information
jrauh01 committed Dec 10, 2024
1 parent d2c9eca commit d10f689
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions database/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,19 @@ func NewDbFromConfig(c *Config, logger *logging.Logger, connectorCallbacks Retry
}
db = sqlx.NewDb(sql.OpenDB(NewConnector(connector, logger, connectorCallbacks)), PostgreSQL)
case "sqlite":
addr = c.Database
var (
name = c.Database
mode = ""
)

if strings.Contains(c.Database, ":memory:") && c.Database != ":memory:" {
name = strings.Split(c.Database, ":memory:")[1]
mode = "mode=memory&"
}

addr = fmt.Sprintf("file:%s?%scache=shared", name, mode)

liteDb, err := sql.Open(SQLite, fmt.Sprintf("file:%s?cache=shared", c.Database))
liteDb, err := sql.Open(SQLite, addr)
if err != nil {
return nil, errors.Wrap(err, "can't open sqlite database")
}
Expand Down

0 comments on commit d10f689

Please sign in to comment.