patterns

package
v0.0.0-...-076d96f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 25, 2012 License: BSD-2-Clause-Views Imports: 4 Imported by: 0

Documentation

Overview

Package pattern contains (should, lol) reusable database patterns. These functions are intended as inner building blocks of saner APIs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteById

func DeleteById(db *mgo.Database, collname string, id interface{}) error

Removes a doc by id, takes care about non stripped string ids.

func FieldStartsWith

func FieldStartsWith(db *mgo.Database, collname, fieldname, val string) ([]interface{}, error)

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 IncAll

func IncAll(db *mgo.Database, collname string, ids []bson.ObjectId, fieldnames []string, num int) error

func PullFromAll

func PullFromAll(db *mgo.Database, collname, fieldname string, value interface{}) error

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 Satisfies

func Satisfies(db *mgo.Database, collname string, id bson.ObjectId, query map[string]interface{}) (bool, error)

func ToIdWithCare

func ToIdWithCare(id interface{}) bson.ObjectId

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL