basic

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: 6 Imported by: 0

Documentation

Overview

A collection of independent helper functions mainly related to database operations.

Index

Constants

View Source
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 CalcMiss

func CalcMiss(rule map[string]interface{}, dat map[string]interface{}) []string

Calculate missing fields, we compare dat to r.

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

func Copy(db *mgo.Database, from_collname, to_collname string, id bson.ObjectId) error

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

func CreateCopy(db *mgo.Database, collname, sortfield string) bson.ObjectId

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

func CreateOptCopy(db *mgo.Database) bson.ObjectId

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 Delete

func Delete(db *mgo.Database, collname string, id bson.ObjectId) error

Deletes a document from a given collection by moving it to collname + "_deleted".

func ExtractIds

func ExtractIds(dat map[string][]string, keys []string) ([]string, error)

Helps to extract a bunch of ids from the UI input.

func Find

func Find(db *mgo.Database, coll string, id interface{}) map[string]interface{}

Find by Id.

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 Inud

func Inud(db *mgo.Database, ev ifaces.Event, dat map[string]interface{}, coll, op, id string) error

Insert, and update/delete, by Id.

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 Move

func Move(db *mgo.Database, from_collname, to_collname string, id bson.ObjectId) error

Moves document from one collection to another.

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 Slug

func Slug(rule map[string]interface{}, dat map[string]interface{})

If rule has slugs, then dat will already contain it if it was sent from UI.

func StripId

func StripId(str_id string) string

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

func ToIdWithCare(id interface{}) bson.ObjectId

Converts a given interface value to an ObjectId with utmost care, taking all possible malformedness into account.

Types

This section is empty.

Jump to

Keyboard shortcuts

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