swirl/dao/mongo/setting.go
2018-03-27 16:32:30 +08:00

31 lines
593 B
Go

package mongo
import (
"github.com/cuigh/swirl/model"
"github.com/globalsign/mgo"
"github.com/globalsign/mgo/bson"
)
const settingID int32 = 0
func (d *Dao) SettingGet() (setting *model.Setting, err error) {
d.do(func(db *database) {
setting = &model.Setting{}
err = db.C("setting").FindId(settingID).One(setting)
if err == mgo.ErrNotFound {
err = nil
}
})
return
}
func (d *Dao) SettingUpdate(setting *model.Setting) (err error) {
d.do(func(db *database) {
update := bson.M{
"$set": setting,
}
_, err = db.C("setting").UpsertId(settingID, update)
})
return
}