Documentation ¶
Overview ¶
A collection of independent helper functions mainly related to database operations.
Index ¶
- Constants
- func CalcMiss(rule map[string]interface{}, dat map[string]interface{}) []string
- func Convert(x interface{}) interface{}
- func Copy(db *mgo.Database, from_collname, to_collname string, id bson.ObjectId) error
- func CreateCopy(db *mgo.Database, collname, sortfield string) bson.ObjectId
- func CreateOptCopy(db *mgo.Database) bson.ObjectId
- func DateAndAuthor(rule map[string]interface{}, dat map[string]interface{}, user_id bson.ObjectId, ...)
- func Delete(db *mgo.Database, collname string, id bson.ObjectId) error
- func ExtractIds(dat map[string][]string, keys []string) ([]string, error)
- func Find(db *mgo.Database, coll string, id interface{}) map[string]interface{}
- func GetDraftParent(db *mgo.Database, coll string, draft_id bson.ObjectId) (parent, root, last_version bson.ObjectId, err error)
- func GetParentTroughContent(db *mgo.Database, coll string, content_id bson.ObjectId) (parent, root bson.ObjectId, err error)
- func Inud(db *mgo.Database, ev ifaces.Event, dat map[string]interface{}, ...) error
- func InudOpt(db *mgo.Database, ev ifaces.Event, dat map[string]interface{}, ...) error
- func InudVersion(db *mgo.Database, ev ifaces.Event, dat map[string]interface{}, ...) error
- func Move(db *mgo.Database, from_collname, to_collname string, id bson.ObjectId) error
- func SaveVersion(db *mgo.Database, coll string, version_id, live_id, parent, root bson.ObjectId) error
- func Slug(rule map[string]interface{}, dat map[string]interface{})
- func StripId(str_id string) string
- func ToIdWithCare(id interface{}) bson.ObjectId
Constants ¶
const ( Delete_collection_postfix = "_deleted" Version_collection_postfix = "_version" Created_by = "_users_created_by" Created = "created" Last_modified_by = "_users_last_modified_by" Last_modified = "last_modified" Version_datefield = "version_date" Fresh = "fresh" // Saved into a version, pointing to the "living" doc. Prev_version = "previous_version" // Goes into the "living" doc. )
Variables ¶
This section is empty.
Functions ¶
func Convert ¶
func Convert(x interface{}) interface{}
Converts all bson.M s to map[string]interface{} s. Usually called on db query results. Will become obsolete when the mgo driver will return map[string]interface{} maps instead of bson.M ones.
func Copy ¶
TODO: with_upsert: true at deletion (you dont care if it is already copied to the deleted collection, false at restoration: you dont want to overwrite any document in the actual live collection.
func CreateCopy ¶
Creates a copy of the most up to date document in collname (sorted by sortfield), and returns it's ObjectId for further updates. Used in situations where we want to handle a series of documents as immutable values, like the the documents in the "options" collection.
func CreateOptCopy ¶
Called before install and uninstall automatically, and you must call it by hand every time you want to modify the option document.
func DateAndAuthor ¶
func DateAndAuthor(rule map[string]interface{}, dat map[string]interface{}, user_id bson.ObjectId, updating bool)
Kind of an extension of the extract module. Handles author fields (created_by, last_modified_by), And time fields (created, last_modified)
func ExtractIds ¶
Helps to extract a bunch of ids from the UI input.
func GetDraftParent ¶
func GetDraftParent(db *mgo.Database, coll string, draft_id bson.ObjectId) (parent, root, last_version bson.ObjectId, err error)
Query draft by id. Parent will be itself the draft, but we must extract the root from the draft. If it has none, he will become the root. Return the last_version of the parent draft too (used at content/model/versions.go)
func GetParentTroughContent ¶
func GetParentTroughContent(db *mgo.Database, coll string, content_id bson.ObjectId) (parent, root bson.ObjectId, err error)
Query content by id. Get "pointing_to" field, query that version. Return the version as parent. Return its root as root, or itself as root if it has none.
func InudOpt ¶
func InudOpt(db *mgo.Database, ev ifaces.Event, dat map[string]interface{}, coll, op, id string, version bool) error
At update uses $set, does not replace document.
func InudVersion ¶
func InudVersion(db *mgo.Database, ev ifaces.Event, dat map[string]interface{}, coll, op, id string) error
Same as Inud, but takes into account versioning and drafts.
func SaveVersion ¶
func SaveVersion(db *mgo.Database, coll string, version_id, live_id, parent, root bson.ObjectId) error
Version id for insert, live id for querying.
func StripId ¶
From user interface the ObjectId can come in a form (OjbectIdHex("era3232322332dsds33")) which is inappropriate as an ObjectId input. This strips the unnecessary parts. Once the UI will be universally cleared from those unnecessary string parts it will become obsolete. (See IdsToStrings)
func ToIdWithCare ¶
Converts a given interface value to an ObjectId with utmost care, taking all possible malformedness into account.
Types ¶
This section is empty.