Add --sqlite option (#4841)
This commit is contained in:
parent
b26cf6d9b9
commit
59bcc1fa52
5 changed files with 12 additions and 2 deletions
|
|
@ -38,7 +38,7 @@ var conf = config{
|
|||
},
|
||||
Database: dbConfig{
|
||||
Type: "sqlite",
|
||||
Dsn: "~/.evcc/evcc.db?_pragma=busy_timeout(5000)",
|
||||
Dsn: "~/.evcc/evcc.db",
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,9 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
flagSqlite = "sqlite"
|
||||
flagSqliteDescription = "Sqlite database file"
|
||||
|
||||
flagHeaders = "log-headers"
|
||||
flagHeadersDescription = "Log headers"
|
||||
|
||||
|
|
|
|||
|
|
@ -53,6 +53,8 @@ func init() {
|
|||
|
||||
rootCmd.PersistentFlags().Bool(flagHeaders, false, flagHeadersDescription)
|
||||
|
||||
rootCmd.PersistentFlags().String(flagSqlite, "", flagSqliteDescription)
|
||||
|
||||
// config file options
|
||||
rootCmd.PersistentFlags().StringP("log", "l", "info", "Log level (fatal, error, warn, info, debug, trace)")
|
||||
bindP(rootCmd, "log")
|
||||
|
|
|
|||
|
|
@ -85,6 +85,10 @@ func configureEnvironment(cmd *cobra.Command, conf config) (err error) {
|
|||
|
||||
// setup persistence
|
||||
if err == nil && conf.Database.Dsn != "" {
|
||||
if flag := cmd.Flags().Lookup(flagSqlite); flag.Changed {
|
||||
conf.Database.Type = "sqlite"
|
||||
conf.Database.Dsn = flag.Value.String()
|
||||
}
|
||||
err = configureDatabase(conf.Database)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,8 @@ func New(driver, dsn string) (*gorm.DB, error) {
|
|||
if err := os.MkdirAll(filepath.Dir(file), os.ModePerm); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dialect = sqlite.Open(file)
|
||||
// avoid busy errors
|
||||
dialect = sqlite.Open(file + "?_pragma=busy_timeout(5000)")
|
||||
// case "postgres":
|
||||
// dialect = postgres.Open(dsn)
|
||||
// case "mysql":
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue