package chapters import ( "git.aiterp.net/rpdata/api/internal/store" "git.aiterp.net/rpdata/api/models" "github.com/globalsign/mgo" ) var collection *mgo.Collection func find(query interface{}) (models.Chapter, error) { chapter := models.Chapter{} err := collection.Find(query).One(&chapter) return chapter, err } func list(query interface{}) ([]models.Chapter, error) { chapters := make([]models.Chapter, 0, 8) err := collection.Find(query).Sort("createdDate").All(&chapters) if err != nil { return nil, err } return chapters, nil } func init() { store.HandleInit(func(db *mgo.Database) { collection = db.C("story.chapters") collection.EnsureIndexKey("storyId") collection.EnsureIndexKey("author") collection.EnsureIndexKey("createdDate") }) }