Files
db-sqlite/config.go
T

29 lines
1.1 KiB
Go
Raw Normal View History

package sqlite
// Config holds SQLite connection settings. Path is required; all other fields
// have production-safe defaults via [DefaultConfig].
type Config struct {
// Path is the SQLite file path. Use ":memory:" for in-memory databases.
Path string `env:"EINHERJAR_SQLITE_PATH,required"`
MaxOpenConns int `env:"EINHERJAR_SQLITE_MAX_OPEN_CONNS" envDefault:"1"`
MaxIdleConns int `env:"EINHERJAR_SQLITE_MAX_IDLE_CONNS" envDefault:"1"`
// Pragmas are appended to the DSN as query parameters.
// Default enables WAL journal mode, 5-second busy timeout, and FK enforcement.
Pragmas string `env:"EINHERJAR_SQLITE_PRAGMAS" envDefault:"?_journal=WAL&_timeout=5000&_fk=true"`
}
// DefaultConfig returns a Config with all optional fields set to production-safe
// defaults. Callers must supply Path.
func DefaultConfig() Config {
return Config{
MaxOpenConns: 1,
MaxIdleConns: 1,
Pragmas: "?_journal=WAL&_timeout=5000&_fk=true",
}
}
// DSN constructs the SQLite connection string from the configuration.
func (c Config) DSN() string {
return c.Path + c.Pragmas
}