mirror of
https://github.com/cuigh/swirl
synced 2024-12-31 16:23:13 +00:00
31 lines
593 B
Go
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
|
|
}
|