(q bson.M, results *Nodes, order string, options map[string]int)
| 67 | } |
| 68 | |
| 69 | func dbFind(q bson.M, results *Nodes, order string, options map[string]int) (count int, err error) { |
| 70 | session := db.Connection.Session.Copy() |
| 71 | defer session.Close() |
| 72 | c := session.DB(conf.MONGODB_DATABASE).C("Nodes") |
| 73 | if order == "" { |
| 74 | order = "created_on" |
| 75 | } |
| 76 | if limit, has := options["limit"]; has { |
| 77 | if offset, has := options["offset"]; has { |
| 78 | query := c.Find(q).Sort(order) |
| 79 | count, err = query.Count() |
| 80 | if err != nil { |
| 81 | count = 0 |
| 82 | return |
| 83 | } |
| 84 | err = query.Limit(limit).Skip(offset).All(results) |
| 85 | if err != nil { |
| 86 | return |
| 87 | } |
| 88 | } else { |
| 89 | err = errors.New("store.db.Find options limit and offset must be used together") |
| 90 | return |
| 91 | } |
| 92 | } else { |
| 93 | err = c.Find(q).Sort(order).All(results) |
| 94 | if err != nil { |
| 95 | return |
| 96 | } |
| 97 | } |
| 98 | results.DBInit() |
| 99 | return |
| 100 | } |
| 101 | |
| 102 | func DbFindDistinct(q bson.M, d string) (results interface{}, err error) { |
| 103 | session := db.Connection.Session.Copy() |
no test coverage detected