Documentation
¶
Index ¶
- Constants
- Variables
- func ContainsField(fields []string, field string) bool
- func JoinField(key, originField string) string
- func JoinIndexKey(engineName string, index Index) string
- func JoinKey(engineName, originKey string) string
- type CacheProxy
- type CacheProxySession
- type DatabaseProxy
- type DatabaseProxySession
- type Engine
- type ErrorHandler
- type Field
- type FieldGetter
- type FieldList
- type FieldSetter
- type FieldSlice
- type GetOption
- type Index
- type Int16Keys
- type Int32Keys
- type Int64Keys
- type Int8Keys
- type IntKeys
- type InterfaceKeys
- type KeyList
- type RangeLexResult
- type RangeOption
- type RangeResult
- type ReadonlyTable
- type Record
- type Repository
- type Session
- type StringKeys
- type Table
- type TableListContainer
- type TableMeta
- type Tx
- type Uint16Keys
- type Uint32Keys
- type Uint64Keys
- type Uint8Keys
- type UintKeys
- type View
Constants ¶
const ( Unused = 0 ErrorHandlerDepth = 4 InvalidRank = -1 InvalidScore = math.MinInt64 MinScore = math.MinInt64 MaxScore = math.MaxInt64 )
const NullCacheProxy = nullCacheProxy(0)
const NullDatabaseProxy = nullDatabaseProxy(0)
Variables ¶
var ( ErrNotFound = errors.New("not found") ErrFieldNotFound = errors.New("field not found") ErrUnexpectedLength = errors.New("unexpected length") ErrViewRefFieldMissing = errors.New("view ref field missing") ErrTableNotFoundInView = errors.New("table not found in view") ErrTypeAssert = errors.New("type assert failed") ErrNotImplemented = errors.New("not implemented") )
Functions ¶
func ContainsField ¶
func JoinIndexKey ¶
Types ¶
type CacheProxy ¶
type CacheProxy interface {
NewSession() CacheProxySession
}
type CacheProxySession ¶
type CacheProxySession interface {
Tx
HDel(table string, fields ...string) (int64, error)
HExists(table, field string) (bool, error)
HIncrBy(table, field string, incr int64) (int64, error)
HMGet(table string, fields ...string) ([]interface{}, error)
HMSet(table string, fields map[string]string) (string, error)
Delete(keys ...string) (int64, error)
ZAdd(key string, members ...redis.Z) (int64, error)
ZRem(key string, members ...interface{}) (int64, error)
ZRank(key, member string) (int64, error)
ZScore(key, member string) (int64, error)
// range APIs
ZRange(key string, start, stop int64) (RangeResult, error)
ZRangeWithScores(key string, start, stop int64) (RangeResult, error)
ZRangeByScore(key string, opt redis.ZRangeBy) (RangeResult, error)
ZRangeByLex(key string, opt redis.ZRangeBy) (RangeLexResult, error)
ZRangeByScoreWithScores(key string, opt redis.ZRangeBy) (RangeResult, error)
ZRevRange(key string, start, stop int64) (RangeResult, error)
ZRevRangeWithScores(key string, start, stop int64) (RangeResult, error)
ZRevRangeByScore(key string, opt redis.ZRangeBy) (RangeResult, error)
ZRevRangeByLex(key string, opt redis.ZRangeBy) (RangeLexResult, error)
ZRevRangeByScoreWithScores(key string, opt redis.ZRangeBy) (RangeResult, error)
}
type DatabaseProxy ¶
type DatabaseProxy interface {
NewSession() DatabaseProxySession
}
type DatabaseProxySession ¶
type Engine ¶
type Engine interface {
Repository
// Cache returns CacheProxy
Cache() CacheProxy
// Database returns DatabaseProxy
Database() DatabaseProxy
// SetErrorHandler sets handler for handling error
SetErrorHandler(eh ErrorHandler)
// AddIndex adds an index, should panic if repeated index name on a same table
AddIndex(index Index)
// NewSession new a session
NewSession() Session
}
func NewEngine ¶
func NewEngine(name string, database DatabaseProxy, cache CacheProxy) Engine
NewEngine creates an engine which named name. Parameter database MUST be not nil, but cache can be nil.
type ErrorHandler ¶
ErrorHandler handles error
type FieldGetter ¶
FieldGetter get value by field
type FieldSetter ¶
FieldGetter set value by field
type FieldSlice ¶
type FieldSlice []string
FieldSlice implements FieldList
func (FieldSlice) Field ¶
func (fs FieldSlice) Field(i int) string
func (FieldSlice) Len ¶
func (fs FieldSlice) Len() int
type GetOption ¶
type GetOption func(*getOptions)
GetOption represents options for Get/Find/FindView operations
func WithSyncFromDatabase ¶
func WithSyncFromDatabase() GetOption
WithSyncFromDatabase returns a GetOption which would get data from database if data not found in cache
type Index ¶
type Index interface {
Name() string
TableMeta() TableMeta
Update(s Session, table ReadonlyTable, key interface{}, updatedFields []string) error
Remove(s Session, keys ...interface{}) error
}
Index represents a sorted set for field of table
type Int64Keys ¶
type Int64Keys []int64
func ToInt64Keys ¶
ToInt64Keys convert KeyList to an Int64Keys which satify filter all keys would be contained if filter is nil
type InterfaceKeys ¶
type InterfaceKeys []interface{}
func (InterfaceKeys) Key ¶
func (keys InterfaceKeys) Key(i int) interface{}
func (InterfaceKeys) Len ¶
func (keys InterfaceKeys) Len() int
type RangeLexResult ¶
type RangeLexResult interface {
KeyList
}
RangeLexResult represents result of range by lex
type RangeOption ¶
type RangeOption func(*rangeOptions)
RangeOption represents options for IndexRange operations
func RangeCount ¶
func RangeCount(count int64) RangeOption
func RangeOffset ¶
func RangeOffset(offset int64) RangeOption
func RangeRev ¶
func RangeRev() RangeOption
func RangeWithScores ¶
func RangeWithScores() RangeOption
type RangeResult ¶
RangeLexResult represents result of range by rank,score etc.
type ReadonlyTable ¶
type ReadonlyTable interface {
TableMeta() TableMeta
Key() interface{}
FieldGetter
}
ReadonlyTable represents a read-only table
type Repository ¶
type Repository interface {
// Name returns database name
Name() string
// Insert inserts new records
Insert(tables ...Table) error
// Update updates specific fields of record
Update(table Table, fields ...string) error
// UpdateByIndexScore updates specific fields of records which satify index score range
UpdateByIndexScore(table Table, index Index, minScore, maxScore int64, fields ...string) (RangeResult, error)
// Find gets records all fields by keys and stores loaded data to container
Find(keys KeyList, container TableListContainer, opts ...GetOption) error
// FindFields gets records specific fields by keys and stores loaded data to container
FindFields(keys KeyList, container TableListContainer, fields ...string) error
FindByIndexScore(index Index, minScore, maxScore int64, container TableListContainer, opts ...GetOption) error
FindFieldsByIndexScore(index Index, minScore, maxScore int64, container TableListContainer, fields ...string) error
// Get gets one record all fields
Get(table Table, opts ...GetOption) (bool, error)
// GetFields gets one record specific fields
GetFields(table Table, fields ...string) (bool, error)
// Remove removes one record
Remove(table ReadonlyTable) error
// RemoveRecords removes records by keys
RemoveRecords(meta TableMeta, keys ...interface{}) error
// Clear removes all records of table
Clear(table string) error
// FindView loads view by keys and stores loaded data to container
FindView(view View, keys KeyList, container TableListContainer, opts ...GetOption) error
// IndexRank gets rank of table key in index, returns InvalidRank if key not found
IndexRank(index Index, key interface{}) (int64, error)
// IndexScore gets score of table key in index, returns InvalidScore if key not found
IndexScore(index Index, key interface{}) (int64, error)
// IndexRange ranges index by rank
IndexRange(index Index, start, stop int64, opts ...RangeOption) (RangeResult, error)
// IndexRangeByScore ranges index by score
IndexRangeByScore(index Index, min, max int64, opts ...RangeOption) (RangeResult, error)
// IndexRangeByLex ranges index by lexicographical
IndexRangeByLex(index Index, min, max string, opts ...RangeOption) (RangeLexResult, error)
// AddRecord adds a record with timestamp
AddRecord(key string, member interface{}, unixstamp int64) error
GetRecordsByTime(key string, startUnixstamp, endUnixstamp int64) (RangeResult, error)
GetRecordsByPage(key string, pageSize int, startRank int64) (RangeResult, error)
}
Repository represents APIs for operating database and/or cache
type Session ¶
type Session interface {
Tx
Repository
Cache() CacheProxySession
Database() DatabaseProxySession
}
type StringKeys ¶
type StringKeys []string
func ToStringKeys ¶
func ToStringKeys(keys KeyList, filter func(string) bool) StringKeys
ToInt64Keys convert KeyList to an StringKeys which satify filter all keys would be contained if filter is nil
func (StringKeys) Key ¶
func (keys StringKeys) Key(i int) interface{}
func (StringKeys) Len ¶
func (keys StringKeys) Len() int
type Table ¶
type Table interface {
ReadonlyTable
SetKey(string) error
FieldSetter
}
Table represents a table in sql database, and hash table in nosql database
type TableListContainer ¶
type TableListContainer interface {
TableMeta() TableMeta
Len() int
New(tableName string, index int, key string) (Table, error)
}
TableListContainer is a linear container holds and creates Table
type TableMeta ¶
type TableMeta interface {
// Name returns name of table
Name() string
// Key returns name of key field
Key() string
// Fields returns names of all fields except key field
Fields() []string
}
TableMeta holds table meta information
type Uint16Keys ¶
type Uint16Keys []uint16
func (Uint16Keys) Key ¶
func (keys Uint16Keys) Key(i int) interface{}
func (Uint16Keys) Len ¶
func (keys Uint16Keys) Len() int
type Uint32Keys ¶
type Uint32Keys []uint32
func (Uint32Keys) Key ¶
func (keys Uint32Keys) Key(i int) interface{}
func (Uint32Keys) Len ¶
func (keys Uint32Keys) Len() int
type Uint64Keys ¶
type Uint64Keys []uint64
func (Uint64Keys) Key ¶
func (keys Uint64Keys) Key(i int) interface{}
func (Uint64Keys) Len ¶
func (keys Uint64Keys) Len() int