goploy/model/SystemConfigModel.go
2021-08-20 11:26:37 +08:00

43 lines
860 B
Go

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.
Select("id, `key`, value").
From(systemConfigTable).
Where(sq.Eq{"`key`": sc.Key}).
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,
}).
Where(sq.Eq{"`key`": sc.Key})
_, err := builder.RunWith(DB).Exec()
return err
}