aboutsummaryrefslogtreecommitdiff
path: root/internal/sqlutil/connection_manager.go
diff options
context:
space:
mode:
authorTill <2353100+S7evinK@users.noreply.github.com>2023-07-19 13:37:04 +0200
committerGitHub <noreply@github.com>2023-07-19 13:37:04 +0200
commit297479ea4993f00a60600232485275d2c57462fe (patch)
tree35670b8efeebcaf4caf1d482d8183c2d1fc7e6f7 /internal/sqlutil/connection_manager.go
parenta01faee17c331db76317a38dd28c1ae85e5ed1f6 (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.go16
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 {