-
Notifications
You must be signed in to change notification settings - Fork 4
/
interfaces.go
92 lines (69 loc) · 2.64 KB
/
interfaces.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package db
import (
"github.com/ottemo/commerce/env"
"github.com/ottemo/commerce/utils"
"time"
)
// Package global 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
)
// InterfaceDBEngine represents interface to access database engine
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)
}
// InterfaceDBCollection interface to access particular table/collection of database
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
}
// InterfaceDBConnector interface to connect to database and keep connection alive
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)
}