2018-04-27 13:17:00 +00:00
|
|
|
package bolt
|
|
|
|
|
|
|
|
import (
|
2021-12-06 12:24:22 +00:00
|
|
|
"context"
|
|
|
|
|
2021-12-23 11:28:31 +00:00
|
|
|
"github.com/cuigh/swirl/dao"
|
2018-04-27 13:17:00 +00:00
|
|
|
)
|
|
|
|
|
2021-12-16 08:11:16 +00:00
|
|
|
const Setting = "setting"
|
|
|
|
|
2021-12-23 11:28:31 +00:00
|
|
|
func (d *Dao) SettingGetAll(ctx context.Context) (settings []*dao.Setting, err error) {
|
2021-12-16 08:11:16 +00:00
|
|
|
err = d.each(Setting, func(v []byte) error {
|
2021-12-23 11:28:31 +00:00
|
|
|
s := &dao.Setting{}
|
2021-12-16 08:11:16 +00:00
|
|
|
err = decode(v, s)
|
2021-12-06 12:24:22 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-04-27 13:17:00 +00:00
|
|
|
|
2021-12-06 12:24:22 +00:00
|
|
|
settings = append(settings, s)
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-12-23 11:28:31 +00:00
|
|
|
func (d *Dao) SettingGet(ctx context.Context, id string) (setting *dao.Setting, err error) {
|
|
|
|
setting = &dao.Setting{}
|
2021-12-16 08:11:16 +00:00
|
|
|
err = d.get(Setting, id, setting)
|
|
|
|
if err == ErrNoRecords {
|
|
|
|
return nil, nil
|
|
|
|
} else if err != nil {
|
|
|
|
setting = nil
|
2018-04-27 13:17:00 +00:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-12-23 11:28:31 +00:00
|
|
|
func (d *Dao) SettingUpdate(ctx context.Context, setting *dao.Setting) (err error) {
|
2021-12-16 08:11:16 +00:00
|
|
|
return d.replace(Setting, setting.ID, setting)
|
2018-04-27 13:17:00 +00:00
|
|
|
}
|