Documentation ¶
Overview ¶
Package pattern contains (should, lol) reusable database patterns. These functions are intended as inner building blocks of saner APIs.
Index ¶
- func DeleteById(db *mgo.Database, collname string, id interface{}) error
- func FieldStartsWith(db *mgo.Database, collname, fieldname, val string) ([]interface{}, error)
- func FindChildren(db *mgo.Database, children_coll, parent_fk_field string, ...) ([]interface{}, error)
- func FindChildrenByParent(db *mgo.Database, parent_coll string, parent_q map[string]interface{}, ...) ([]interface{}, error)
- func FindEq(db *mgo.Database, coll, field string, value interface{}) (map[string]interface{}, error)
- func FindQ(db *mgo.Database, coll string, query map[string]interface{}) (map[string]interface{}, error)
- func IncAll(db *mgo.Database, collname string, ids []bson.ObjectId, fieldnames []string, ...) error
- func PullFromAll(db *mgo.Database, collname, fieldname string, value interface{}) error
- func Satisfies(db *mgo.Database, collname string, id bson.ObjectId, ...) (bool, error)
- func ToIdWithCare(id interface{}) bson.ObjectId
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeleteById ¶
Removes a doc by id, takes care about non stripped string ids.
func FieldStartsWith ¶
func FindChildren ¶
func FindChildren(db *mgo.Database, children_coll, parent_fk_field string, parent_id bson.ObjectId, additional_query map[string]interface{}) ([]interface{}, error)
See *1 below.
func FindChildrenByParent ¶
func FindChildrenByParent(db *mgo.Database, parent_coll string, parent_q map[string]interface{}, children_coll, parent_fk_field string, children_q map[string]interface{}) ([]interface{}, error)
[1] This is highly experimental, not used ATM, dont look here, its ugly.
Finds a document in [parent_coll] collection based on [field] [value] equality, then queries [children_coll] for documents which has the _id of that document in their parent_fk_field. Returns children list only, no parent.
func FindEq ¶
func FindEq(db *mgo.Database, coll, field string, value interface{}) (map[string]interface{}, error)
Finds a doc by field-value equality.
func FindQ ¶
func FindQ(db *mgo.Database, coll string, query map[string]interface{}) (map[string]interface{}, error)
Finds a doc by query.
func PullFromAll ¶
Takes a collection, a field and a value and pulls that value from all docs in the collection. Caution, it does not take care about string id values, or even worse, non stripped string id values.
func ToIdWithCare ¶
Types ¶
This section is empty.