/
dalFaction.go
46 lines (38 loc) · 1.13 KB
/
dalFaction.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package dal
import (
"github.com/GwentAPI/gwentapi/dataLayer/models"
"gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
)
type (
DalFaction struct {
collection *mgo.Collection
}
)
func NewDalFaction(ds *DataStore) *DalFaction {
return &DalFaction{ds.Collection("factions")}
}
func (dc DalFaction) Fetch(uuid []byte) (*models.Faction, error) {
result := models.Faction{}
err := dc.collection.Find(bson.M{"uuid": uuid}).One(&result)
return &result, err
}
func (dc DalFaction) FetchWithName(name string) (*models.Faction, error) {
result := models.Faction{}
err := dc.collection.Find(bson.M{"name": name}).One(&result)
return &result, err
}
func (dc DalFaction) FetchAll() (*[]models.Faction, error) {
results := []models.Faction{}
err := dc.collection.Find(nil).Sort("name").All(&results)
return &results, err
}
func (dc DalFaction) FetchAllPaging(limit int, offset int) (*[]models.Faction, error) {
results := []models.Faction{}
err := dc.collection.Find(nil).Limit(limit).Sort("name").Skip(offset).All(&results)
return &results, err
}
func (dc DalFaction) Count() (int, error) {
result, err := dc.collection.Count()
return result, err
}