mysql

package
v1.4.5-alpha1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2019 License: MPL-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package mysql is a default MySQL implementation for Ottemo. It provides "InterfaceDBEngine" implementation declared in "github.com/ottemo/commerce/db" package.

Package stands on a top of "github.com/go-sql-driver/mysql" package.

Index

Constants

View Source
const (
	ConstConnectionValidateInterval = time.Second * 10 // timer interval to ping connection and refresh it by perforce

	ConstUseUUIDids = true // flag which indicates to use UUID "_id" column type instead of default integer
	ConstDebugSQL   = true // flag which indicates to perform log on each SQL operation
	ConstDebugFile  = "mysql.log"

	ConstFilterGroupStatic  = "static"  // name for static filter, ref. to AddStaticFilter(...)
	ConstFilterGroupDefault = "default" // name for default filter, ref. to by AddFilter(...)

	ConstCollectionNameColumnInfo = "collection_column_info" // table name to hold Ottemo types of columns

	ConstErrorModule = "db/mysql"
	ConstErrorLevel  = env.ConstErrorLevelService
)

Package global constants

Variables

View Source
var (

	// ConstSQLNameValidator is a regex expression used to check names used within SQL queries
	ConstSQLNameValidator = regexp.MustCompile("^[A-Za-z_][A-Za-z0-9_]*$")
)

Package global variables

Functions

func GetDBType

func GetDBType(ColumnType string) (string, error)

GetDBType returns type used inside mysql for given general name

Types

type DBCollection

type DBCollection struct {
	Name string

	ResultColumns []string
	FilterGroups  map[string]*StructDBFilterGroup
	Order         []string

	Limit string
}

DBCollection is a InterfaceDBCollection implementer

func (*DBCollection) AddColumn

func (it *DBCollection) AddColumn(columnName string, columnType string, indexed bool) error

AddColumn adds new attribute(column) to current collection(table)

func (*DBCollection) AddFilter

func (it *DBCollection) AddFilter(ColumnName string, Operator string, Value interface{}) error

AddFilter adds selection filter to current collection(table) 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, except static

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(column) 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(columns) available for current collection(table)

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 record from DB by it's id

func (*DBCollection) RemoveColumn

func (it *DBCollection) RemoveColumn(columnName string) error

RemoveColumn removes attribute(column) to current collection(table)

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 {
	// contains filtered or unexported fields
}

DBEngine is a InterfaceDBEngine implementer

func (*DBEngine) AfterConnect

func (it *DBEngine) AfterConnect(srcConnectionParams interface{}) error

AfterConnect makes initialization of DB engine

func (*DBEngine) Connect

func (it *DBEngine) Connect(srcConnectionParams interface{}) error

Connect establishes DB connection

func (*DBEngine) CreateCollection

func (it *DBEngine) CreateCollection(collectionName string) error

CreateCollection creates cllection(table) by it's name

func (*DBEngine) GetCollection

func (it *DBEngine) GetCollection(collectionName string) (db.InterfaceDBCollection, error)

GetCollection returns collection(table) by name or creates new one

func (*DBEngine) GetConnectionParams

func (it *DBEngine) GetConnectionParams() interface{}

GetConnectionParams returns configured DB connection params

func (*DBEngine) GetEngineName

func (it *DBEngine) GetEngineName() string

GetEngineName returns DBEngine name (InterfaceDBConnector)

func (*DBEngine) GetName

func (it *DBEngine) GetName() string

GetName returns current DB engine name

func (*DBEngine) GetValidationInterval

func (it *DBEngine) GetValidationInterval() time.Duration

GetValidationInterval returns delay between Ping

func (*DBEngine) HasCollection

func (it *DBEngine) HasCollection(collectionName string) bool

HasCollection checks if collection(table) already exists

func (*DBEngine) IsConnected

func (it *DBEngine) IsConnected() bool

IsConnected returns connection status

func (*DBEngine) LogConnection

func (it *DBEngine) LogConnection(message string)

LogConnection outputs message to log

func (*DBEngine) Ping

func (it *DBEngine) Ping() error

Ping checks connection alive

func (*DBEngine) RawQuery

func (it *DBEngine) RawQuery(query string) (map[string]interface{}, error)

RawQuery returns collection(table) by name or creates new one

func (*DBEngine) Reconnect

func (it *DBEngine) Reconnect(connectionParams interface{}) error

Reconnect tries to reconnect to DB

func (*DBEngine) SetConnected

func (it *DBEngine) SetConnected(connected bool)

SetConnected sets connection status

type RowMap

type RowMap map[string]interface{}

RowMap - represents row of data from database

type StructDBFilterGroup

type StructDBFilterGroup struct {
	Name         string
	FilterValues []string
	ParentGroup  string
	OrSequence   bool
}

StructDBFilterGroup is a structure to hold information of named collection filter

Jump to

Keyboard shortcuts

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