Switched to purer libraries
This commit is contained in:
parent
8fa8bb4c3a
commit
9496947f01
21 changed files with 390 additions and 316 deletions
|
|
@ -2,16 +2,17 @@ package main
|
|||
|
||||
import (
|
||||
// External
|
||||
werr "git.gibonuddevalla.se/go/wrappederror"
|
||||
werr "git.ahall.se/go/wrappederror"
|
||||
"github.com/jackc/pgx/v5"
|
||||
|
||||
// Standard
|
||||
"database/sql"
|
||||
"context"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Configuration struct {
|
||||
timezoneLocation *time.Location
|
||||
Settings map[string]string
|
||||
Settings map[string]string
|
||||
}
|
||||
|
||||
var smonConfig Configuration
|
||||
|
|
@ -19,8 +20,8 @@ var smonConfig Configuration
|
|||
func SmonConfigInit() (cfg Configuration, err error) {
|
||||
cfg.Settings = make(map[string]string, 8)
|
||||
|
||||
var rows *sql.Rows
|
||||
rows, err = service.Db.Conn.Query(`SELECT * FROM public.configuration`)
|
||||
var rows pgx.Rows
|
||||
rows, err = db.Query(context.Background(), `SELECT * FROM public.configuration`)
|
||||
if err != nil {
|
||||
err = werr.Wrap(err)
|
||||
return
|
||||
|
|
@ -46,7 +47,7 @@ func (cfg *Configuration) Validate() (err error) {
|
|||
mandatorySettings := []string{"THEME", "TIMEZONE"}
|
||||
for _, settingsKey := range mandatorySettings {
|
||||
if _, found := cfg.Settings[settingsKey]; !found {
|
||||
return werr.New("Configuration missing setting '%s' in database", settingsKey)
|
||||
return werr.New("Configuration missing setting '%s' in database", settingsKey)
|
||||
}
|
||||
}
|
||||
return
|
||||
|
|
@ -63,7 +64,7 @@ func (cfg *Configuration) Timezone() *time.Location {
|
|||
|
||||
func (cfg *Configuration) SetTheme(theme string) (err error) {
|
||||
cfg.Settings["THEME"] = theme
|
||||
_, err = service.Db.Conn.Exec(`UPDATE public.configuration SET value=$1 WHERE setting='THEME'`, theme)
|
||||
_, err = db.Exec(context.Background(), `UPDATE public.configuration SET value=$1 WHERE setting='THEME'`, theme)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -74,7 +75,7 @@ func (cfg *Configuration) SetTimezone(tz string) (err error) {
|
|||
return werr.Wrap(err).WithData(tz)
|
||||
}
|
||||
|
||||
_, err = service.Db.Conn.Exec(`UPDATE public.configuration SET value=$1 WHERE setting='TIMEZONE'`, tz)
|
||||
_, err = db.Exec(context.Background(), `UPDATE public.configuration SET value=$1 WHERE setting='TIMEZONE'`, tz)
|
||||
if err != nil {
|
||||
return werr.Wrap(err).WithData(tz)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue