diff options
author | Till <2353100+S7evinK@users.noreply.github.com> | 2023-07-19 13:37:04 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-19 13:37:04 +0200 |
commit | 297479ea4993f00a60600232485275d2c57462fe (patch) | |
tree | 35670b8efeebcaf4caf1d482d8183c2d1fc7e6f7 /internal/sqlutil/connection_manager.go | |
parent | a01faee17c331db76317a38dd28c1ae85e5ed1f6 (diff) |
Use pointer when passing the connection manager around (#3152)
As otherwise existing connections aren't reused.
Diffstat (limited to 'internal/sqlutil/connection_manager.go')
-rw-r--r-- | internal/sqlutil/connection_manager.go | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/internal/sqlutil/connection_manager.go b/internal/sqlutil/connection_manager.go index 934a2954..4933cfaf 100644 --- a/internal/sqlutil/connection_manager.go +++ b/internal/sqlutil/connection_manager.go @@ -29,24 +29,26 @@ type Connections struct { processContext *process.ProcessContext } -func NewConnectionManager(processCtx *process.ProcessContext, globalConfig config.DatabaseOptions) Connections { - return Connections{ +func NewConnectionManager(processCtx *process.ProcessContext, globalConfig config.DatabaseOptions) *Connections { + return &Connections{ globalConfig: globalConfig, processContext: processCtx, } } func (c *Connections) Connection(dbProperties *config.DatabaseOptions) (*sql.DB, Writer, error) { - writer := NewDummyWriter() - if dbProperties.ConnectionString.IsSQLite() { - writer = NewExclusiveWriter() - } var err error if dbProperties.ConnectionString == "" { // if no connectionString was provided, try the global one dbProperties = &c.globalConfig } - if dbProperties.ConnectionString != "" || c.db == nil { + + writer := NewDummyWriter() + if dbProperties.ConnectionString.IsSQLite() { + writer = NewExclusiveWriter() + } + + if dbProperties.ConnectionString != "" && c.db == nil { // Open a new database connection using the supplied config. c.db, err = Open(dbProperties, writer) if err != nil { |