GraphQL API and utilities for the rpdata project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

36 lines
776 B

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")
})
}