swirl/dao/mongo/event.go
cuigh ca0789ac4e Change mgo pkg
Since original pkg is unmaintained
2018-01-19 16:21:46 +08:00

36 lines
724 B
Go

package mongo
import (
"github.com/cuigh/swirl/model"
"github.com/globalsign/mgo/bson"
)
func (d *Dao) EventList(args *model.EventListArgs) (events []*model.Event, count int, err error) {
d.do(func(db *database) {
query := bson.M{}
if args.Type != "" {
query["type"] = args.Type
}
if args.Name != "" {
query["name"] = args.Name
}
q := db.C("event").Find(query)
count, err = q.Count()
if err != nil {
return
}
events = []*model.Event{}
err = q.Sort("-time").Skip(args.PageSize * (args.PageIndex - 1)).Limit(args.PageSize).All(&events)
})
return
}
func (d *Dao) EventCreate(event *model.Event) (err error) {
d.do(func(db *database) {
err = db.C("event").Insert(event)
})
return
}