Documentation ¶
Overview ¶
Package mongo is a default mongoDB implementation for Ottemo. It provides "InterfaceDBEngine" implementation declared in "github.com/ottemo/commerce/db" package.
Package stands on a top of "gopkg.in/mgo.v2" package.
MongoDB is the only database that harnesses the innovations of NoSQL (flexibility, scalability, performance) and builds on the commerce of relational databases (expressive query language, secondary indexes, strong consistency).
Index ¶
- Constants
- func BsonDToString(input bson.D) string
- func ConvertMapToDoc(inputMap map[string]interface{}) bson.D
- type DBCollection
- func (it *DBCollection) AddColumn(ColumnName string, ColumnType string, indexed bool) error
- func (it *DBCollection) AddFilter(ColumnName string, Operator string, Value interface{}) error
- func (it *DBCollection) AddGroupFilter(GroupName string, ColumnName string, Operator string, Value interface{}) error
- func (it *DBCollection) AddSort(ColumnName string, Desc bool) error
- func (it *DBCollection) AddStaticFilter(ColumnName string, Operator string, Value interface{}) error
- func (it *DBCollection) ClearFilters() error
- func (it *DBCollection) ClearSort() error
- func (it *DBCollection) Count() (int, error)
- func (it *DBCollection) Delete() (int, error)
- func (it *DBCollection) DeleteByID(id string) error
- func (it *DBCollection) Distinct(columnName string) ([]interface{}, error)
- func (it *DBCollection) GetColumnType(ColumnName string) string
- func (it *DBCollection) HasColumn(ColumnName string) bool
- func (it *DBCollection) Iterate(iteratorFunc func(record map[string]interface{}) bool) error
- func (it *DBCollection) ListColumns() map[string]string
- func (it *DBCollection) Load() ([]map[string]interface{}, error)
- func (it *DBCollection) LoadByID(id string) (map[string]interface{}, error)
- func (it *DBCollection) RemoveColumn(ColumnName string) error
- func (it *DBCollection) RemoveFilterGroup(GroupName string) error
- func (it *DBCollection) Save(Item map[string]interface{}) (string, error)
- func (it *DBCollection) SetLimit(Offset int, Limit int) error
- func (it *DBCollection) SetResultColumns(columns ...string) error
- func (it *DBCollection) SetupFilterGroup(groupName string, orSequence bool, parentGroup string) error
- type DBEngine
- func (it *DBEngine) AfterConnect(srcConnectionParams interface{}) error
- func (it *DBEngine) Connect(srcConnectionParams interface{}) error
- func (it *DBEngine) CreateCollection(CollectionName string) error
- func (it *DBEngine) GetCollection(CollectionName string) (db.InterfaceDBCollection, error)
- func (it *DBEngine) GetConnectionParams() interface{}
- func (it *DBEngine) GetEngineName() string
- func (it *DBEngine) GetName() string
- func (it *DBEngine) GetValidationInterval() time.Duration
- func (it *DBEngine) HasCollection(CollectionName string) bool
- func (it *DBEngine) IsConnected() bool
- func (it *DBEngine) LogConnection(message string)
- func (it *DBEngine) Output(calldepth int, s string) error
- func (it *DBEngine) Ping() error
- func (it *DBEngine) RawQuery(query string) (map[string]interface{}, error)
- func (it *DBEngine) Reconnect(connectionParams interface{}) error
- func (it *DBEngine) SetConnected(connected bool)
- type StructDBFilterGroup
Constants ¶
const ( ConstConnectionValidateInterval = time.Second * 10 // timer interval to ping connection and refresh it by perforce ConstMongoDebug = false // flag which indicates to perform log on each operation ConstFilterGroupStatic = "static" // name for static filter, ref. to AddStaticFilter(...) ConstFilterGroupDefault = "default" // name for default filter, ref. to by AddFilter(...) ConstCollectionNameColumnInfo = "collection_column_info" // collection name to hold Ottemo types of attributes ConstErrorModule = "db/mongo" ConstErrorLevel = env.ConstErrorLevelService )
Package global constants
Variables ¶
This section is empty.
Functions ¶
func BsonDToString ¶
BsonDToString converts bson.D to readable form, mostly used for debug
func ConvertMapToDoc ¶
ConvertMapToDoc is a recursive function that converts map[string]interface{} to bson.D so map keys order is static and alphabetically sorted
Types ¶
type DBCollection ¶
type DBCollection struct { Name string FilterGroups map[string]*StructDBFilterGroup Sort []string ResultAttributes []string Limit int Offset int // contains filtered or unexported fields }
DBCollection is a implementer of InterfaceDBCollection
func (*DBCollection) AddColumn ¶
func (it *DBCollection) AddColumn(ColumnName string, ColumnType string, indexed bool) error
AddColumn adds new attribute to current collection
func (*DBCollection) AddFilter ¶
func (it *DBCollection) AddFilter(ColumnName string, Operator string, Value interface{}) error
AddFilter adds selection filter to current collection object
func (*DBCollection) AddGroupFilter ¶
func (it *DBCollection) AddGroupFilter(GroupName string, ColumnName string, Operator string, Value interface{}) error
AddGroupFilter adds selection filter to specific filter group (all filter groups will be joined before db query)
func (*DBCollection) AddSort ¶
func (it *DBCollection) AddSort(ColumnName string, Desc bool) error
AddSort adds sorting for current collection
func (*DBCollection) AddStaticFilter ¶
func (it *DBCollection) AddStaticFilter(ColumnName string, Operator string, Value interface{}) error
AddStaticFilter adds selection filter that will not be cleared by ClearFilters() function
func (*DBCollection) ClearFilters ¶
func (it *DBCollection) ClearFilters() error
ClearFilters removes all filters that were set for current collection
func (*DBCollection) ClearSort ¶
func (it *DBCollection) ClearSort() error
ClearSort removes any sorting that was set for current collection
func (*DBCollection) Count ¶
func (it *DBCollection) Count() (int, error)
Count returns count of rows matching current select statement
func (*DBCollection) Delete ¶
func (it *DBCollection) Delete() (int, error)
Delete removes records that matches current select statement from DB, returns amount of affected rows
func (*DBCollection) DeleteByID ¶
func (it *DBCollection) DeleteByID(id string) error
DeleteByID removes record from DB by is's id
func (*DBCollection) Distinct ¶
func (it *DBCollection) Distinct(columnName string) ([]interface{}, error)
Distinct returns distinct values of specified attribute
func (*DBCollection) GetColumnType ¶
func (it *DBCollection) GetColumnType(ColumnName string) string
GetColumnType returns SQL like type of attribute in current collection, or if not present ""
func (*DBCollection) HasColumn ¶
func (it *DBCollection) HasColumn(ColumnName string) bool
HasColumn checks attribute presence in current collection
func (*DBCollection) Iterate ¶
func (it *DBCollection) Iterate(iteratorFunc func(record map[string]interface{}) bool) error
Iterate applies [iterator] function to each record, stops on return false
func (*DBCollection) ListColumns ¶
func (it *DBCollection) ListColumns() map[string]string
ListColumns returns attributes available for current collection
func (*DBCollection) Load ¶
func (it *DBCollection) Load() ([]map[string]interface{}, error)
Load loads records from DB for current collection and filter if it set
func (*DBCollection) LoadByID ¶
func (it *DBCollection) LoadByID(id string) (map[string]interface{}, error)
LoadByID loads one record from DB by record _id
func (*DBCollection) RemoveColumn ¶
func (it *DBCollection) RemoveColumn(ColumnName string) error
RemoveColumn removes attribute from current collection
- for MoongoDB it means update "collection_column_info" collection and, update all objects of current collection to exclude attribute
func (*DBCollection) RemoveFilterGroup ¶
func (it *DBCollection) RemoveFilterGroup(GroupName string) error
RemoveFilterGroup removes filter group for collection
func (*DBCollection) Save ¶
func (it *DBCollection) Save(Item map[string]interface{}) (string, error)
Save stores record in DB for current collection
func (*DBCollection) SetLimit ¶
func (it *DBCollection) SetLimit(Offset int, Limit int) error
SetLimit results pagination
func (*DBCollection) SetResultColumns ¶
func (it *DBCollection) SetResultColumns(columns ...string) error
SetResultColumns limits column selection for Load() and LoadByID()function
func (*DBCollection) SetupFilterGroup ¶
func (it *DBCollection) SetupFilterGroup(groupName string, orSequence bool, parentGroup string) error
SetupFilterGroup setups filter group params for collection
type DBEngine ¶
type DBEngine struct { DBName string // contains filtered or unexported fields }
DBEngine is a implementer of InterfaceDBEngine
func (*DBEngine) AfterConnect ¶
AfterConnect makes initialization of DB engine
func (*DBEngine) CreateCollection ¶
CreateCollection creates cllection by it's name
func (*DBEngine) GetCollection ¶
func (it *DBEngine) GetCollection(CollectionName string) (db.InterfaceDBCollection, error)
GetCollection returns collection by name or creates new one
func (*DBEngine) GetConnectionParams ¶
func (it *DBEngine) GetConnectionParams() interface{}
GetConnectionParams returns configured DB connection params
func (*DBEngine) GetEngineName ¶
GetEngineName returns DBEngine name (InterfaceDBConnector)
func (*DBEngine) GetValidationInterval ¶
GetValidationInterval returns delay between Ping
func (*DBEngine) HasCollection ¶
HasCollection checks if collection already exists
func (*DBEngine) IsConnected ¶
IsConnected returns connection status
func (*DBEngine) LogConnection ¶
LogConnection outputs message to log
func (*DBEngine) RawQuery ¶
RawQuery executes raw query for DB engine.
This function makes eval commang on mongo db (http://docs.mongodb.org/manual/reference/command/eval/#dbcmd.eval) so if you are using "db.collection.find()" - it returns cursor object, do not forget to add ".toArray()", i.e. "db.collection.find().toArray()"
func (*DBEngine) SetConnected ¶
SetConnected sets connection status