2021-07-17 11:12:17 +08:00
|
|
|
package model
|
|
|
|
|
|
|
|
import (
|
|
|
|
sq "github.com/Masterminds/squirrel"
|
|
|
|
)
|
|
|
|
|
|
|
|
const systemConfigTable = "`system_config`"
|
|
|
|
|
|
|
|
// SystemConfig -
|
|
|
|
type SystemConfig struct {
|
|
|
|
ID int64 `json:"id"`
|
|
|
|
Key string `json:"key"`
|
|
|
|
Value string `json:"value"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetDataByKey -
|
|
|
|
func (sc SystemConfig) GetDataByKey() (SystemConfig, error) {
|
|
|
|
var systemConfig SystemConfig
|
|
|
|
err := sq.
|
2021-08-20 11:26:37 +08:00
|
|
|
Select("id, `key`, value").
|
2021-07-17 11:12:17 +08:00
|
|
|
From(systemConfigTable).
|
2021-08-20 11:26:37 +08:00
|
|
|
Where(sq.Eq{"`key`": sc.Key}).
|
2021-07-17 11:12:17 +08:00
|
|
|
RunWith(DB).
|
|
|
|
QueryRow().
|
|
|
|
Scan(&systemConfig.ID, &systemConfig.Key, &systemConfig.Value)
|
|
|
|
if err != nil {
|
|
|
|
return systemConfig, err
|
|
|
|
}
|
|
|
|
return systemConfig, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// EditRowByKey -
|
|
|
|
func (sc SystemConfig) EditRowByKey() error {
|
|
|
|
builder := sq.
|
|
|
|
Update(systemConfigTable).
|
|
|
|
SetMap(sq.Eq{
|
|
|
|
"value": sc.Value,
|
|
|
|
}).
|
2021-08-20 11:26:37 +08:00
|
|
|
Where(sq.Eq{"`key`": sc.Key})
|
2021-07-17 11:12:17 +08:00
|
|
|
_, err := builder.RunWith(DB).Exec()
|
|
|
|
return err
|
|
|
|
}
|