diff --git a/sqldb/config.go b/sqldb/config.go index 59801dbea..ebf386f54 100644 --- a/sqldb/config.go +++ b/sqldb/config.go @@ -31,6 +31,22 @@ type SqliteConfig struct { QueryConfig `group:"query" namespace:"query"` } +const ( + // defaultBusyTimeoutMs is the default busy_timeout value in + // milliseconds, used when no BusyTimeout is configured. + defaultBusyTimeoutMs = 5000 +) + +// busyTimeoutMs returns the busy_timeout value in milliseconds. If +// BusyTimeout is not set, it returns the default value. +func (s *SqliteConfig) busyTimeoutMs() int64 { + if s.BusyTimeout > 0 { + return s.BusyTimeout.Milliseconds() + } + + return defaultBusyTimeoutMs +} + // Validate checks that the SqliteConfig values are valid. func (p *SqliteConfig) Validate() error { if err := p.QueryConfig.Validate(true); err != nil { diff --git a/sqldb/sqlite.go b/sqldb/sqlite.go index 2b2f7be13..fc724e939 100644 --- a/sqldb/sqlite.go +++ b/sqldb/sqlite.go @@ -70,7 +70,7 @@ func NewSqliteStore(cfg *SqliteConfig, dbPath string) (*SqliteStore, error) { }, { name: "busy_timeout", - value: "5000", + value: fmt.Sprintf("%d", cfg.busyTimeoutMs()), }, { // With the WAL mode, this ensures that we also do an