database

package
v0.11.3 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConnectFailed = "database connect fail"

	BEFORE_INSERT = 0x01
	BEFORE_DELETE = 0x02
	BEFORE_UPDATE = 0x03
	BEFORE_FETCH  = 0x04

	AFTER_INSERT = 0x05
	AFTER_DELETE = 0x06
	AFTER_UPDATE = 0x07
	AFTER_FETCH  = 0x08
)

Variables

This section is empty.

Functions

func LoadTable

func LoadTable(table Table, data map[string]interface{}) (bool, error)

LoadTable alias of Map2Table

func Map2Table

func Map2Table(table Table, data map[string]interface{}) (bool, error)

func New

func New(conf interface{}) drivers.DBDriver

New

func Table2Map

func Table2Map(table Table) map[string]interface{}

Types

type CTable

type CTable interface {
	Table
	GetTimeOut() time.Duration
	GetCacheKey() string
	Where() map[string]interface{}
}

CTable Table's cache version

type CacheTable

type CacheTable struct {
	SmtQueue chan map[string]interface{}
	Cache    cache.Cache
	DataTable
}

CacheTable

func NewCacheTable

func NewCacheTable(cache cache.Cache, dbConf config.Connect) *CacheTable

NewCacheTable instantiate

func (*CacheTable) Fetch

func (ct *CacheTable) Fetch(table CTable) error

Fetch @feature fetch from cache, if not exist, get from db and update cache

func (*CacheTable) Save

func (ct *CacheTable) Save(table CTable) error

Save @feature save to cache, and add request to queue

func (*CacheTable) Trash

func (ct *CacheTable) Trash(table CTable) error

Trash @feature delete cache, and add request to queue

func (*CacheTable) Update

func (ct *CacheTable) Update(table CTable) error

Update @feature update cache and add request to queue

type DataTable

type DataTable struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewDataTable

func NewDataTable(conf interface{}) *DataTable

NewDataTable @conf two possible format:1. yaml config file path,2. map including all configuration

func (*DataTable) CountTable

func (dt *DataTable) CountTable(table Table, params map[string]interface{}) (int64, error)

func (*DataTable) DeleteTable

func (dt *DataTable) DeleteTable(table Table) (bool, error)

DeleteTable delete based on primary key

func (*DataTable) FetchTable

func (dt *DataTable) FetchTable(table Table, params map[string]interface{}) error

FetchTable

@params table @params params, refer to utils/database/drivers/mysql.go

func (*DataTable) FetchTables

func (dt *DataTable) FetchTables(tables interface{}, params map[string]interface{}) (interface{}, error)

FetchTables

@params tables, eg. tables := []table.PP @params params, refer to utils/database/drivers/mysql.go @return []Table

func (*DataTable) GetDriver

func (dt *DataTable) GetDriver() drivers.DBDriver

func (*DataTable) InsertTable

func (dt *DataTable) InsertTable(table Table) (bool, error)

InsertTable

@params table, must including data to insert @return bool success/failure,error

func (*DataTable) IsConnected

func (dt *DataTable) IsConnected() bool

func (*DataTable) StoreTable

func (dt *DataTable) StoreTable(table Table) (bool, error)

StoreTable

@notice if table has auto-incremental id primary key, action is update, otherwise action is insert @params table, must have data to store @return bool success/failure,error

func (*DataTable) SumTable

func (dt *DataTable) SumTable(table Table, field string, params map[string]interface{}) (int64, error)

SumTable based on column

func (*DataTable) UpdateTable

func (dt *DataTable) UpdateTable(table Table) (bool, error)

UpdateTable

@params table, must include data to update @return bool success/failure, error

type Table

type Table interface {
	TableName() string
	PrimaryKey() []string
	SetData(data map[string]interface{}) (bool, error)
	Event(event int, dt *DataTable)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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