Documentation ¶
Index ¶
- Constants
- func GetCollections(servername, dbname string) (collnames []string, err error)
- func IsCollectionExists(servername, dbname, collname string) (exists bool, err error)
- func ServerConnect(params map[string]string) (err error)
- func ServersDisconnect()
- type CollIndexes
- type DAO
- func (dao *DAO) Close()
- func (dao *DAO) CountAll() (n int, err error)
- func (dao *DAO) DebugIndexes()
- func (dao *DAO) Delete(id bson.ObjectId) (err error)
- func (dao *DAO) DeleteAll(are, you, sure bool) (count int, err error)
- func (dao *DAO) DeleteBy(kvals ...interface{}) (count int, err error)
- func (dao *DAO) DeleteMany(ids []bson.ObjectId) (count int, err error)
- func (dao *DAO) DropCollection(are, you, sure bool) (err error)
- func (dao *DAO) EnsureIndexes()
- func (dao *DAO) FindAs(obj interface{}, equals map[string]interface{}, fields ...string) (err error)
- func (dao *DAO) FindManyAs(objs interface{}, equals map[string]interface{}, fields ...string) (err error)
- func (dao *DAO) FindManyByIntervalAs(objs interface{}, dateKey string, ps, pe time.Time, fields ...string) (err error)
- func (dao *DAO) FindManyByPeriodAs(objs interface{}, psKey, peKey string, ps, pe time.Time, fields ...string) (err error)
- func (dao *DAO) GetAllAs(objs interface{}, fields ...string) (err error)
- func (dao *DAO) GetAllAsMap(fields ...string) (res []map[string]interface{}, err error)
- func (dao *DAO) GetAs(obj interface{}, id bson.ObjectId, fields ...string) (err error)
- func (dao *DAO) GetAsMap(id bson.ObjectId, fields ...string) (obj map[string]interface{}, err error)
- func (dao *DAO) GetManyAs(objs interface{}, ids []bson.ObjectId, fields ...string) (err error)
- func (dao *DAO) Open(servername, dbname, collname string, idxs *CollIndexes)
- func (dao *DAO) Quirk_GetOneAs(obj interface{}, fields ...string) (err error)
- func (dao *DAO) Save(forceID bool, objs ...interface{}) (err error)
- func (dao *DAO) SetStrongMode()
- func (dao *DAO) Update(id bson.ObjectId, params map[string]interface{}) (err error)
- func (dao *DAO) Update_ArrayAdd(id bson.ObjectId, addTo string, addObj interface{}) (err error)
- func (dao *DAO) Update_ArrayAddMany(id bson.ObjectId, addTo string, addObjs []interface{}) (err error)
- func (dao *DAO) Update_ArrayPull(id bson.ObjectId, pullFrom string, pullObj interface{}) (err error)
- func (dao *DAO) Update_ArrayPullMany(id bson.ObjectId, pullFrom string, pullObjs []interface{}) (err error)
- func (dao *DAO) Update_ArrayPush(id bson.ObjectId, pushTo string, pushObj interface{}) (err error)
- func (dao *DAO) Update_ArrayPushMany(id bson.ObjectId, pushTo string, pushObjs []interface{}) (err error)
- func (dao *DAO) Update_ArraysPullAddMany(id bson.ObjectId, pullFrom string, pullObjs []interface{}, addTo string, ...) (err error)
- func (dao *DAO) Update_ArraysPullPush(id bson.ObjectId, pullFrom string, pullObj interface{}, pushTo string, ...) (err error)
- func (dao *DAO) Update_ArraysPullPushMany(id bson.ObjectId, pullFrom string, pullObjs []interface{}, pushTo string, ...) (err error)
- func (dao *DAO) Update_Set(id bson.ObjectId, key string, obj interface{}) (err error)
- func (dao *DAO) Upsert(selector, update interface{}) (err error)
- type M
- type MS
- type MongoLogger
Constants ¶
const ( // Parameter keys KEY_DB_SERVER_ID = "id" KEY_DB_SERVER = "server" //KEY_DB_PORT = "port" KEY_DB_OPTIONS = "options" KEY_DB_MODE = "mode" KEY_DB_LOG = "log" )
Variables ¶
This section is empty.
Functions ¶
func GetCollections ¶
Lists all collections present.
func IsCollectionExists ¶
Checks if given collection exists.
func ServerConnect ¶
Creates DB server connection. Provide map with the following values: "id": internal server ID, use "_" for default single server "server": ie "localhost" (not implemented) "port": optional port number "options": ie "connect=direct" "mode": ie "monotonic" "log": empty for no log, any string value will activate logging
Types ¶
type CollIndexes ¶
type CollIndexes struct {
// contains filtered or unexported fields
}
func BuildIndexes ¶
func BuildIndexes(midxs ...mgo.Index) (idxs *CollIndexes)
Builds struct contaning an array of Mongo indexes. Indexes set to un-initialized.
func (*CollIndexes) Indexes ¶
func (ci *CollIndexes) Indexes() []mgo.Index
type DAO ¶
type DAO struct { Coll *mgo.Collection // contains filtered or unexported fields }
func (*DAO) DebugIndexes ¶
func (dao *DAO) DebugIndexes()
Debug method that prints active indexes for given collection.
func (*DAO) DeleteBy ¶
Deletes object from collection by given criteria. Kvals is an array of key-value pairs like so: "name", "Joe", "age", 99, ...
func (*DAO) DeleteMany ¶
Deletes many objects by IDs.
func (*DAO) DropCollection ¶
Drops collection. No turning back!
func (*DAO) EnsureIndexes ¶
func (dao *DAO) EnsureIndexes()
Ensures multiple indexes. Error is suppressed yet reported.
func (*DAO) FindAs ¶
func (dao *DAO) FindAs(obj interface{}, equals map[string]interface{}, fields ...string) (err error)
Finds an object from collection by given equals 'and' criteria. Obj must be a pointer to a struct.
func (*DAO) FindManyAs ¶
func (dao *DAO) FindManyAs(objs interface{}, equals map[string]interface{}, fields ...string) (err error)
Finds many objects matching equals 'and' criteria. Objs must be a pointer to an empty array of structs.
func (*DAO) FindManyByIntervalAs ¶
func (dao *DAO) FindManyByIntervalAs(objs interface{}, dateKey string, ps, pe time.Time, fields ...string) (err error)
Finds many objects matching dateKey to the specified time period. Note that interval is [ps, pe) meaning pe is EXCLUDED. Objs must be a pointer to an empty array of structs.
func (*DAO) FindManyByPeriodAs ¶
func (dao *DAO) FindManyByPeriodAs(objs interface{}, psKey, peKey string, ps, pe time.Time, fields ...string) (err error)
Finds many objects matching 'ps' and 'pe' field keys to be inside the specified time period. Objs must be a pointer to an empty array of structs.
func (*DAO) GetAllAs ¶
Gets all documents. Fields is an array of fields to be fetched. Objs must be a pointer to an empty array of structs.
func (*DAO) GetAllAsMap ¶
Gets all documents. Fields is an array of fields to be fetched.
func (*DAO) GetAsMap ¶
func (dao *DAO) GetAsMap(id bson.ObjectId, fields ...string) (obj map[string]interface{}, err error)
Gets document as a map. Fields is an array of fields to be fetched.
func (*DAO) GetManyAs ¶
Gets many documents matched by IDs into provided array. Fields is an array of fields to be fetched. Objs must be a pointer to an empty array of structs.
func (*DAO) Open ¶
func (dao *DAO) Open(servername, dbname, collname string, idxs *CollIndexes)
Opens new session with collection. Don't forget to close.
func (*DAO) Quirk_GetOneAs ¶
Gets random one.
func (*DAO) Save ¶
Saves objecst(s). Force ID means generate ID before passing to Mongo. Useful if you need this ID right away. Method checks if ID already exists and doesn't overwrite it in this case. IMPORTANT: Force ID mode only supports pointers to structs. ObjectId must be a pointer too. XXX Still not 100% how objs... work. Better to save one obj at a time.
func (*DAO) Update ¶
Updates (set/unset) by map. Nil means don't touch.
For string values: Empty string means unset. Not empty string means set.
Objects passed as they are.
func (*DAO) Update_ArrayAdd ¶
Adds addObj element to array addTo only if it is not already there.
func (*DAO) Update_ArrayAddMany ¶
func (dao *DAO) Update_ArrayAddMany(id bson.ObjectId, addTo string, addObjs []interface{}) (err error)
Adds addObjs elements to addTo array only if they are not already there.
func (*DAO) Update_ArrayPull ¶
func (dao *DAO) Update_ArrayPull(id bson.ObjectId, pullFrom string, pullObj interface{}) (err error)
Removes pullFrom array element that matches pullObj.
func (*DAO) Update_ArrayPullMany ¶
func (dao *DAO) Update_ArrayPullMany(id bson.ObjectId, pullFrom string, pullObjs []interface{}) (err error)
Removes pullFrom array elements that matches pullObjs.
func (*DAO) Update_ArrayPush ¶
Adds pushObj element to array pushTo.
func (*DAO) Update_ArrayPushMany ¶
func (dao *DAO) Update_ArrayPushMany(id bson.ObjectId, pushTo string, pushObjs []interface{}) (err error)
Adds pushObjs elements to array pushTo.
func (*DAO) Update_ArraysPullAddMany ¶
func (dao *DAO) Update_ArraysPullAddMany(id bson.ObjectId, pullFrom string, pullObjs []interface{}, addTo string, addObjs []interface{}) (err error)
Removes pullObjs elements from pullFrom array. Adds addObjs elements to addTo array only if they are not already there.
func (*DAO) Update_ArraysPullPush ¶
func (dao *DAO) Update_ArraysPullPush(id bson.ObjectId, pullFrom string, pullObj interface{}, pushTo string, pushObj interface{}) (err error)
Removes pullObj element from pullFrom array. Adds pushObj element to pushTo array.
func (*DAO) Update_ArraysPullPushMany ¶
func (dao *DAO) Update_ArraysPullPushMany(id bson.ObjectId, pullFrom string, pullObjs []interface{}, pushTo string, pushObjs []interface{}) (err error)
Removes pullObjs elements from pullFrom array. Adds pushObjs elements to pushTo array.
func (*DAO) Update_Set ¶
Sets single field to given value. Provide empty string to unset the field regardless of field's type.