Skip to content

Commit cff8836

Browse files
ViktorT-11ziggie1984
authored andcommitted
sqldb/v2: add MaxIdleConnections & ConnMaxLifetime sqlite opts
1 parent 1819b98 commit cff8836

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

sqldb/v2/config.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ const (
3131
//
3232
//nolint:ll
3333
type SqliteConfig struct {
34-
Timeout time.Duration `long:"timeout" description:"The time after which a database query should be timed out."`
35-
BusyTimeout time.Duration `long:"busytimeout" description:"The maximum amount of time to wait for a database connection to become available for a query."`
36-
MaxConnections int `long:"maxconnections" description:"The maximum number of open connections to the database."`
37-
PragmaOptions []string `long:"pragmaoptions" description:"A list of pragma options to set on a database connection. For example, 'auto_vacuum=incremental'. Note that the flag must be specified multiple times if multiple options are to be set."`
38-
SkipMigrations bool `long:"skipmigrations" description:"Skip applying migrations on startup."`
34+
Timeout time.Duration `long:"timeout" description:"The time after which a database query should be timed out."`
35+
BusyTimeout time.Duration `long:"busytimeout" description:"The maximum amount of time to wait for a database connection to become available for a query."`
36+
MaxConnections int `long:"maxconnections" description:"The maximum number of open connections to the database."`
37+
MaxIdleConnections int `long:"maxidleconnections" description:"Max number of idle connections to keep in the connection pool."`
38+
ConnMaxLifetime time.Duration `long:"connmaxlifetime" description:"Max amount of time a connection can be reused for before it is closed. Valid time units are {s, m, h}."`
39+
PragmaOptions []string `long:"pragmaoptions" description:"A list of pragma options to set on a database connection. For example, 'auto_vacuum=incremental'. Note that the flag must be specified multiple times if multiple options are to be set."`
40+
SkipMigrations bool `long:"skipmigrations" description:"Skip applying migrations on startup."`
3941

4042
// SkipMigrationDbBackup if true, then a backup of the database will not
4143
// be created before applying migrations.

sqldb/v2/sqlite.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,19 @@ func NewSqliteStore(cfg *SqliteConfig, dbPath string) (*SqliteStore, error) {
141141
maxConns = cfg.MaxConnections
142142
}
143143

144+
maxIdleConns := defaultMaxIdleConns
145+
if cfg.MaxIdleConnections > 0 {
146+
maxIdleConns = cfg.MaxIdleConnections
147+
}
148+
149+
connMaxLifetime := defaultConnMaxLifetime
150+
if cfg.ConnMaxLifetime > 0 {
151+
connMaxLifetime = cfg.ConnMaxLifetime
152+
}
153+
144154
db.SetMaxOpenConns(maxConns)
145-
db.SetMaxIdleConns(defaultMaxIdleConns)
146-
db.SetConnMaxLifetime(defaultConnMaxLifetime)
155+
db.SetMaxIdleConns(maxIdleConns)
156+
db.SetConnMaxLifetime(connMaxLifetime)
147157

148158
s := &SqliteStore{
149159
Config: cfg,

0 commit comments

Comments
 (0)