Documentation ¶
Overview ¶
Package sqlite is a default SQLite implementation for Ottemo. It provides "InterfaceDBEngine" implementation declared in "github.com/ottemo/commerce/db" package.
Package stands on a top of "github.com/mxk/go-sqlite/sqlite3" package.
SQLite is a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine. SQLite is the most widely deployed SQL database engine in the world. The source code for SQLite is in the public domain.
Index ¶
- Constants
- Variables
- func GetDBType(ColumnType string) (string, error)
- 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) Ping() error
- func (it *DBEngine) RawQuery(query string) (map[string]interface{}, error)
- func (it *DBEngine) Reconnect(srcConnectionParams 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 ConstUseUUIDids = true // flag which indicates to use UUID "_id" column type instead of default integer ConstDebugSQL = false // flag which indicates to perform log on each SQL operation 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/sqlite" ConstErrorLevel = env.ConstErrorLevelService )
Package global constants
Variables ¶
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 ¶
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)
- sqlite do not have alter DROP COLUMN statements so it is hard task...
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 ¶
AfterConnect makes initialization of DB engine
func (*DBEngine) CreateCollection ¶
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 ¶
GetEngineName returns DBEngine name (InterfaceDBConnector)
func (*DBEngine) GetValidationInterval ¶
GetValidationInterval returns delay between Ping
func (*DBEngine) HasCollection ¶
HasCollection checks if collection(table) already exists
func (*DBEngine) IsConnected ¶
IsConnected returns connection status
func (*DBEngine) LogConnection ¶
LogConnection outputs message to log
func (*DBEngine) SetConnected ¶
SetConnected sets connection status