Documentation ¶
Overview ¶
Package db represents database services abstraction layer. It provides a set of interfaces and helpers to interact with database storage services.
So, when package decides to store something in database it should work with this package instead of trying to interact with concrete database engine (as Ottemo supposing ability to work with different databases).
Providing Ottemo with a new database engine supposes implementation of "InterfaceDBEngine" with following registration for db package.
For database type specification you should refer this package for possible types.
Example: -------- collection, err := db.GetCollection( myCollectionName ) if err != nil { return env.ErrorDispatch(err) } collection.AddColumn("customer_id", db.ConstTypeID, false) collection.AddColumn("customer_email", db.TypeWPrecision(db.ConstTypeVarchar, 100), true) collection.AddColumn("bonus_code", db.ConstTypeInteger, false) collection.AddColumn("bonus_amount", db.ConstTypeInteger, false)
Index ¶
- Constants
- func ConvertTypeFromDbToGo(value interface{}, valueType string) interface{}
- func OnDatabaseStart() error
- func RegisterDBEngine(newEngine InterfaceDBEngine) error
- func RegisterOnDatabaseStart(callback func() error)
- func TypeArrayOf(dataType string) string
- func TypeIsArray(dataType string) bool
- func TypeIsFloat(dataType string) bool
- func TypeIsString(dataType string) bool
- func TypeParse(typeName string) utils.DataType
- func TypeWPrecision(dataType string, precision int) string
- func TypeWPrecisionAndScale(dataType string, precision int, scale int) string
- type DBConnector
- type InterfaceDBCollection
- type InterfaceDBConnector
- type InterfaceDBEngine
Constants ¶
const ( ConstTypeID = utils.ConstDataTypeID ConstTypeBoolean = utils.ConstDataTypeBoolean ConstTypeVarchar = utils.ConstDataTypeVarchar ConstTypeText = utils.ConstDataTypeText ConstTypeInteger = utils.ConstDataTypeInteger ConstTypeDecimal = utils.ConstDataTypeDecimal ConstTypeMoney = utils.ConstDataTypeMoney ConstTypeFloat = utils.ConstDataTypeFloat ConstTypeDatetime = utils.ConstDataTypeDatetime ConstTypeJSON = utils.ConstDataTypeJSON ConstErrorModule = "db" ConstErrorLevel = env.ConstErrorLevelService )
Package global constants
Variables ¶
This section is empty.
Functions ¶
func ConvertTypeFromDbToGo ¶
func ConvertTypeFromDbToGo(value interface{}, valueType string) interface{}
ConvertTypeFromDbToGo returns object that represents GO side value for given valueType
func OnDatabaseStart ¶
func OnDatabaseStart() error
OnDatabaseStart fires database service start event (callback handling)
func RegisterDBEngine ¶
func RegisterDBEngine(newEngine InterfaceDBEngine) error
RegisterDBEngine registers database service in the system
- will cause error if there are couple candidates for that role
func RegisterOnDatabaseStart ¶
func RegisterOnDatabaseStart(callback func() error)
RegisterOnDatabaseStart registers new callback on database service start
func TypeArrayOf ¶
TypeArrayOf shortcut for utils.DataTypeArrayOf
func TypeIsArray ¶
TypeIsArray shortcut for utils.DataTypeIsArray
func TypeIsFloat ¶
TypeIsFloat shortcut for utils.DataTypeIsFloat
func TypeIsString ¶
TypeIsString shortcut for utils.DataTypeIsString
func TypeWPrecision ¶
TypeWPrecision shortcut for utils.DataTypeWPrecision
Types ¶
type DBConnector ¶
type DBConnector struct {
// contains filtered or unexported fields
}
DBConnector takes logic of connection to DB and keeps it alive
func NewDBConnector ¶
func NewDBConnector(connector InterfaceDBConnector) *DBConnector
NewDBConnector returns new DBConnector instance
func (*DBConnector) Connect ¶
func (it *DBConnector) Connect() error
Connect implements connection process algorithm
func (*DBConnector) ConnectAsync ¶
func (it *DBConnector) ConnectAsync() error
ConnectAsync makes connection process asynchronously
type InterfaceDBCollection ¶
type InterfaceDBCollection interface { Load() ([]map[string]interface{}, error) LoadByID(id string) (map[string]interface{}, error) Save(map[string]interface{}) (string, error) Delete() (int, error) DeleteByID(id string) error Iterate(iteratorFunc func(record map[string]interface{}) bool) error Count() (int, error) Distinct(columnName string) ([]interface{}, error) SetupFilterGroup(groupName string, orSequence bool, parentGroup string) error RemoveFilterGroup(groupName string) error AddGroupFilter(groupName string, columnName string, operator string, value interface{}) error AddStaticFilter(columnName string, operator string, value interface{}) error AddFilter(columnName string, operator string, value interface{}) error ClearFilters() error AddSort(columnName string, Desc bool) error ClearSort() error SetResultColumns(columns ...string) error SetLimit(offset int, limit int) error ListColumns() map[string]string GetColumnType(columnName string) string HasColumn(columnName string) bool AddColumn(columnName string, columnType string, indexed bool) error RemoveColumn(columnName string) error }
InterfaceDBCollection interface to access particular table/collection of database
func GetCollection ¶
func GetCollection(CollectionName string) (InterfaceDBCollection, error)
GetCollection returns database collection or error otherwise
type InterfaceDBConnector ¶
type InterfaceDBConnector interface { GetConnectionParams() interface{} Connect(connectionParams interface{}) error AfterConnect(connectionParams interface{}) error Ping() error GetValidationInterval() time.Duration Reconnect(connectionParams interface{}) error IsConnected() bool SetConnected(connected bool) GetEngineName() string LogConnection(message string) }
InterfaceDBConnector interface to connect to database and keep connection alive
type InterfaceDBEngine ¶
type InterfaceDBEngine interface { GetName() string IsConnected() bool CreateCollection(Name string) error GetCollection(Name string) (InterfaceDBCollection, error) HasCollection(Name string) bool RawQuery(query string) (map[string]interface{}, error) }
InterfaceDBEngine represents interface to access database engine
func GetDBEngine ¶
func GetDBEngine() InterfaceDBEngine
GetDBEngine returns currently used database service implementation
Directories ¶
Path | Synopsis |
---|---|
Package mongo is a default mongoDB implementation for Ottemo.
|
Package mongo is a default mongoDB implementation for Ottemo. |
Package mysql is a default MySQL implementation for Ottemo.
|
Package mysql is a default MySQL implementation for Ottemo. |
Package sqlite is a default SQLite implementation for Ottemo.
|
Package sqlite is a default SQLite implementation for Ottemo. |