Documentation ¶
Overview ¶
Copyright 2022 Guan Jianchang. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
Index ¶
- Constants
- Variables
- func ExecTransaction(tx *sql.Tx, query string, args ...interface{}) error
- func FromCache(r DBTableRow, mapField2Val map[string]string) error
- func GenRowObjRegisterFileByCfg(cfg *Config, regFilePath string, regPackName string)
- func InsertTransaction(tx *sql.Tx, query string, args ...interface{}) (int64, error)
- func ToCache(r DBTableRow, fields []string) (map[string]interface{}, error)
- type BaseDBTableRow
- type CacheConf
- type CacheDriver
- func (d *CacheDriver) BLPop(timeout time.Duration, keys ...string) ([]string, error)
- func (d *CacheDriver) Close() error
- func (d *CacheDriver) Del(keys ...string) (int64, error)
- func (d *CacheDriver) Exists(keys ...string) (int64, error)
- func (d *CacheDriver) Expire(key string, expiration time.Duration) (bool, error)
- func (d *CacheDriver) ExpireAt(key string, tm time.Time) (bool, error)
- func (d *CacheDriver) Get(key string) (string, error)
- func (d *CacheDriver) GetDB() *redis.Client
- func (d *CacheDriver) HDel(key string, field string) (int64, error)
- func (d *CacheDriver) HExists(key string, field string) (bool, error)
- func (d *CacheDriver) HGetAll(key string) (map[string]string, error)
- func (d *CacheDriver) HMGet(key string, fields ...string) ([]interface{}, error)
- func (d *CacheDriver) HMSet(key string, fields map[string]interface{}) error
- func (d *CacheDriver) HSet(key string, field string, value interface{}) (bool, error)
- func (d *CacheDriver) HSetNX(key string, field string, value interface{}) (bool, error)
- func (d *CacheDriver) Incr(key string) (int64, error)
- func (d *CacheDriver) Keys(pattern string) ([]string, error)
- func (d *CacheDriver) LLen(key string) (int64, error)
- func (d *CacheDriver) LRange(key string, start int64, stop int64) ([]string, error)
- func (d *CacheDriver) LRem(key string, count int64, value interface{}) (int64, error)
- func (d *CacheDriver) LSet(key string, index int64, value interface{}) error
- func (d *CacheDriver) MGet(keys ...string) ([]interface{}, error)
- func (d *CacheDriver) MSet(pairs ...interface{}) (string, error)
- func (d *CacheDriver) Open(addr string, pwd string, db int) error
- func (d *CacheDriver) Persist(key string) (bool, error)
- func (d *CacheDriver) Publish(channel string, message interface{}) error
- func (d *CacheDriver) RPush(key string, values ...interface{}) error
- func (d *CacheDriver) Set(key string, value interface{}, expiration time.Duration) error
- func (d *CacheDriver) SetNX(key string, value interface{}, expiration time.Duration) (bool, error)
- func (d *CacheDriver) Subscribe(cb RedisSubscribeCb, channels ...string) error
- func (d *CacheDriver) TTL(key string) (time.Duration, error)
- type CacheSaver
- type Cacheable
- type Config
- type CountRow
- type DBConf
- type DBTableRow
- type DataCenter
- func (c *DataCenter) AddCacheDriver(tag string, driver *CacheDriver)
- func (c *DataCenter) AddDbDriver(tag string, driver *DbDriver)
- func (c *DataCenter) AddWorker(tag string, w *DataWorker)
- func (c *DataCenter) BeginTransaction(dbTag string) (*sql.Tx, error)
- func (c *DataCenter) CloseAllCacheDriver()
- func (c *DataCenter) CloseAllDbDriver()
- func (c *DataCenter) Count(tag string, mapper interface{}, extraCond string) (int64, error)
- func (c *DataCenter) GetCacheDriver(tag string) (*CacheDriver, bool)
- func (c *DataCenter) GetDbDriver(tag string) (*DbDriver, bool)
- func (c *DataCenter) GetWorker(tag string) (*DataWorker, bool)
- func (c *DataCenter) Insert(tag string, mapper interface{}, extraCond string) (int64, error)
- func (c *DataCenter) NameExec(dbTag string, query string, mapper interface{}) error
- func (c *DataCenter) NameInsert(dbTag string, query string, mapper interface{}) (int64, error)
- func (c *DataCenter) NameQuery(dbTag string, rowReflectName string, query string, mapper interface{}) ([]DBTableRow, error)
- func (c *DataCenter) ReplaceToDb(tag string, mapper interface{}, extraCond string) error
- func (c *DataCenter) SelectRowFromDb(tag string, mapper interface{}, extraCond string) (DBTableRow, error)
- func (c *DataCenter) SelectRowsFromDb(tag string, mapper interface{}, extraCond string, limitCnt int) ([]DBTableRow, error)
- func (c *DataCenter) Start(saveIntv time.Duration, clearExpireIntv time.Duration)
- func (c *DataCenter) Stop()
- func (c *DataCenter) UpdateToDb(tag string, mapper interface{}, extraCond string) error
- type DataWorker
- func (w *DataWorker) ClearExpireCaches() error
- func (w *DataWorker) Count(mapper interface{}) (int64, error)
- func (w *DataWorker) CountEx(mapper interface{}, extraCond string) (int64, error)
- func (w *DataWorker) DelCacheDataFields(key string, fields ...string) (int64, error)
- func (w *DataWorker) DelCacheDatas(keys ...string) (int64, error)
- func (w *DataWorker) GetAllCacheKeys() ([]string, error)
- func (w *DataWorker) GetCacheData(obj Cacheable, key string, fields ...string) error
- func (w *DataWorker) GetCacheDataToMap(key string, fields ...string) (map[string]string, error)
- func (w *DataWorker) GetDbDriver() (*DbDriver, bool)
- func (w *DataWorker) GetInsertSql() string
- func (w *DataWorker) GetReplaceSql() string
- func (w *DataWorker) GetSelectSql() string
- func (w *DataWorker) GetTableName() string
- func (w *DataWorker) GetUpdateSql() string
- func (w *DataWorker) HasCache() bool
- func (w *DataWorker) HasDb() bool
- func (w *DataWorker) Init(reflectName string, insertTag string, selectTag string, selectKeyTag string, ...) error
- func (w *DataWorker) InsertToDb(mapper interface{}) (int64, error)
- func (w *DataWorker) InsertToDbEx(mapper interface{}, extraCond string) (int64, error)
- func (w *DataWorker) IsOpenAutoSave() bool
- func (w *DataWorker) LoadFromCache(obj Cacheable, key string) error
- func (w *DataWorker) OpenAutoSave()
- func (w *DataWorker) PreloadData(obj Cacheable, mapper interface{}) error
- func (w *DataWorker) ReplaceToDb(mapper interface{}) (int64, error)
- func (w *DataWorker) ReplaceToDbEx(mapper interface{}, extraCond string) (int64, error)
- func (w *DataWorker) SaveCaches() error
- func (w *DataWorker) SelectFromDb(mapper interface{}) (DBTableRow, error)
- func (w *DataWorker) SelectFromDbEx(mapper interface{}, extraCond string) (DBTableRow, error)
- func (w *DataWorker) SelectRowsFromDb(mapper interface{}, limitCnt int) ([]DBTableRow, error)
- func (w *DataWorker) SelectRowsFromDbEx(mapper interface{}, extraCond string, limitCnt int) ([]DBTableRow, error)
- func (w *DataWorker) SetCacheData(obj Cacheable, key string, fields ...string) error
- func (w *DataWorker) SetCacheDataByMap(key string, mapField2Val map[string]interface{}, bMarkUpdate bool) error
- func (w *DataWorker) SetCacheExpire(key string, expiration time.Duration) error
- func (w *DataWorker) SetCacheSaver(saver CacheSaver)
- func (w *DataWorker) SetCacheUpdated(key string)
- func (w *DataWorker) SetInsertSql(insertSql string)
- func (w *DataWorker) SetReplaceSql(replaceSql string)
- func (w *DataWorker) SetSelectSql(selectSql string)
- func (w *DataWorker) SetUpdateSql(updateSql string)
- func (w *DataWorker) Start(saveIntv time.Duration, clearExpireIntv time.Duration)
- func (w *DataWorker) Stop()
- func (w *DataWorker) UpdateToDb(mapper interface{}) (int64, error)
- func (w *DataWorker) UpdateToDbEx(mapper interface{}, extraCond string) (int64, error)
- type DbDriver
- func (d *DbDriver) Begin() (*sql.Tx, error)
- func (d *DbDriver) Close() error
- func (d *DbDriver) CreateTableRow(rowReflectName string) (DBTableRow, error)
- func (d *DbDriver) Exec(query string, args ...interface{}) (sql.Result, error)
- func (d *DbDriver) GetDB() *sqlx.DB
- func (d *DbDriver) NameExec(query string, mapper interface{}) (int64, error)
- func (d *DbDriver) NameInsert(query string, mapper interface{}) (int64, error)
- func (d *DbDriver) NameQuery(rowReflectName string, query string, mapper interface{}) ([]DBTableRow, error)
- func (d *DbDriver) Open(userName string, pwd string, host string, database string, charset string) error
- func (d *DbDriver) Query(sql string) ([]map[string]string, error)
- func (d *DbDriver) ReuseTableRow(rowObj DBTableRow, rowReflectName string)
- func (d *DbDriver) Select(dest interface{}, query string, args ...interface{}) error
- type RedisSubscribeCb
- type StorageConf
- type WorkerConf
Constants ¶
View Source
const ( INSERT_TAG_DEFAULT = "i" SELECT_TAG_DEFAULT = "s" SELECT_KEY_TAG_DEFAULT = "sk" UPDATE_TAG_DEFAULT = "u" UPDATE_KEY_TAG_DEFAULT = "uk" )
View Source
const ( INIT_REUSE_COUNT = 10 MAX_REUSE_COUNT = 100 )
View Source
const (
CACHE_FIELD_UPDATE_TIME = "cache_update_time"
)
Variables ¶
View Source
var ( ErrCacheHasExit = errors.New("has exit") ErrCacheSubscribeFailed = errors.New("subscribe failed") )
View Source
var ( ErrNoDataWorker = errors.New("no data worker") ErrNoDbDriver = errors.New("no db driver") ErrAffectRowZero = errors.New("affect row is zero") )
View Source
var ( ErrNoCache = errors.New("no cache") ErrNoDb = errors.New("no db") ErrWorkerObjectIsNil = errors.New("object is nil") ErrWorkerRowObjIsNil = errors.New("row object is nil") ErrWorkerInsertFieldNotFind = errors.New("insert field not find") ErrWorkerReplaceFieldNotFind = errors.New("insert field and update field not find") ErrWorkerKeyFieldNotDefine = errors.New("key field not define") ErrWorkerCacheNotExist = errors.New("cache data no exist") ErrWorkerDBNotExist = errors.New("db data no data") ErrWorkerFieldNotExist = errors.New("some field not exist") ErrWorkerCacheKeyNotFind = errors.New("cache key not define") ErrWorkerCacheKeyNotString = errors.New("cache key not string") ErrWorkerDBCountUnknownErr = errors.New("unknown error while count") )
View Source
var ( ErrMapperIsNil = errors.New("mapper is nil") ErrNotRowObject = errors.New("not table row object") )
View Source
var Builder = &builder{ logger: yx.NewLogger("odb.Builder"), }
View Source
var RowObjFactory = yx.NewObjectFactory()
Functions ¶
func ExecTransaction ¶ added in v0.3.7
func InsertTransaction ¶ added in v0.3.7
Types ¶
type BaseDBTableRow ¶ added in v0.2.9
type BaseDBTableRow struct { }
type CacheDriver ¶
type CacheDriver struct {
// contains filtered or unexported fields
}
func NewCacheDriver ¶
func NewCacheDriver() *CacheDriver
func (*CacheDriver) Close ¶
func (d *CacheDriver) Close() error
func (*CacheDriver) GetDB ¶ added in v0.3.6
func (d *CacheDriver) GetDB() *redis.Client
func (*CacheDriver) HMGet ¶
func (d *CacheDriver) HMGet(key string, fields ...string) ([]interface{}, error)
func (*CacheDriver) HMSet ¶
func (d *CacheDriver) HMSet(key string, fields map[string]interface{}) error
func (*CacheDriver) HSet ¶
func (d *CacheDriver) HSet(key string, field string, value interface{}) (bool, error)
hash
func (*CacheDriver) HSetNX ¶
func (d *CacheDriver) HSetNX(key string, field string, value interface{}) (bool, error)
func (*CacheDriver) LRem ¶
func (d *CacheDriver) LRem(key string, count int64, value interface{}) (int64, error)
func (*CacheDriver) LSet ¶
func (d *CacheDriver) LSet(key string, index int64, value interface{}) error
func (*CacheDriver) MGet ¶
func (d *CacheDriver) MGet(keys ...string) ([]interface{}, error)
func (*CacheDriver) MSet ¶
func (d *CacheDriver) MSet(pairs ...interface{}) (string, error)
func (*CacheDriver) Publish ¶
func (d *CacheDriver) Publish(channel string, message interface{}) error
func (*CacheDriver) RPush ¶
func (d *CacheDriver) RPush(key string, values ...interface{}) error
list
func (*CacheDriver) Set ¶
func (d *CacheDriver) Set(key string, value interface{}, expiration time.Duration) error
func (*CacheDriver) Subscribe ¶
func (d *CacheDriver) Subscribe(cb RedisSubscribeCb, channels ...string) error
type CacheSaver ¶ added in v0.3.23
type Config ¶
type Config struct { SaveIntv int `json:"save_interval"` ClearIntv int `json:"clear_interval"` Storages []*StorageConf `json:"storages"` }
type CountRow ¶ added in v0.3.6
type CountRow struct { BaseDBTableRow Count int64 `db:"count"` }
type DBTableRow ¶
type DBTableRow interface { Cacheable }
type DataCenter ¶
type DataCenter struct {
// contains filtered or unexported fields
}
func NewDataCenter ¶
func NewDataCenter() *DataCenter
func (*DataCenter) AddCacheDriver ¶
func (c *DataCenter) AddCacheDriver(tag string, driver *CacheDriver)
func (*DataCenter) AddDbDriver ¶
func (c *DataCenter) AddDbDriver(tag string, driver *DbDriver)
func (*DataCenter) AddWorker ¶
func (c *DataCenter) AddWorker(tag string, w *DataWorker)
func (*DataCenter) BeginTransaction ¶ added in v0.3.7
func (c *DataCenter) BeginTransaction(dbTag string) (*sql.Tx, error)
func (*DataCenter) CloseAllCacheDriver ¶
func (c *DataCenter) CloseAllCacheDriver()
func (*DataCenter) CloseAllDbDriver ¶
func (c *DataCenter) CloseAllDbDriver()
func (*DataCenter) Count ¶ added in v0.3.7
func (c *DataCenter) Count(tag string, mapper interface{}, extraCond string) (int64, error)
func (*DataCenter) GetCacheDriver ¶
func (c *DataCenter) GetCacheDriver(tag string) (*CacheDriver, bool)
func (*DataCenter) GetDbDriver ¶
func (c *DataCenter) GetDbDriver(tag string) (*DbDriver, bool)
func (*DataCenter) GetWorker ¶
func (c *DataCenter) GetWorker(tag string) (*DataWorker, bool)
func (*DataCenter) Insert ¶ added in v0.3.7
func (c *DataCenter) Insert(tag string, mapper interface{}, extraCond string) (int64, error)
func (*DataCenter) NameExec ¶ added in v0.3.8
func (c *DataCenter) NameExec(dbTag string, query string, mapper interface{}) error
func (*DataCenter) NameInsert ¶ added in v0.3.8
func (c *DataCenter) NameInsert(dbTag string, query string, mapper interface{}) (int64, error)
func (*DataCenter) NameQuery ¶ added in v0.3.8
func (c *DataCenter) NameQuery(dbTag string, rowReflectName string, query string, mapper interface{}) ([]DBTableRow, error)
func (*DataCenter) ReplaceToDb ¶ added in v0.3.7
func (c *DataCenter) ReplaceToDb(tag string, mapper interface{}, extraCond string) error
func (*DataCenter) SelectRowFromDb ¶ added in v0.3.7
func (c *DataCenter) SelectRowFromDb(tag string, mapper interface{}, extraCond string) (DBTableRow, error)
func (*DataCenter) SelectRowsFromDb ¶ added in v0.3.7
func (c *DataCenter) SelectRowsFromDb(tag string, mapper interface{}, extraCond string, limitCnt int) ([]DBTableRow, error)
func (*DataCenter) Start ¶
func (c *DataCenter) Start(saveIntv time.Duration, clearExpireIntv time.Duration)
func (*DataCenter) Stop ¶
func (c *DataCenter) Stop()
func (*DataCenter) UpdateToDb ¶ added in v0.3.7
func (c *DataCenter) UpdateToDb(tag string, mapper interface{}, extraCond string) error
type DataWorker ¶
type DataWorker struct {
// contains filtered or unexported fields
}
func NewDataWorker ¶
func NewDataWorker(cacheDriver *CacheDriver, cacheKeyName string, dbDriver *DbDriver, tableName string) *DataWorker
func (*DataWorker) ClearExpireCaches ¶
func (w *DataWorker) ClearExpireCaches() error
func (*DataWorker) Count ¶ added in v0.3.6
func (w *DataWorker) Count(mapper interface{}) (int64, error)
func (*DataWorker) CountEx ¶ added in v0.3.6
func (w *DataWorker) CountEx(mapper interface{}, extraCond string) (int64, error)
func (*DataWorker) DelCacheDataFields ¶ added in v0.3.17
func (w *DataWorker) DelCacheDataFields(key string, fields ...string) (int64, error)
func (*DataWorker) DelCacheDatas ¶ added in v0.3.17
func (w *DataWorker) DelCacheDatas(keys ...string) (int64, error)
func (*DataWorker) GetAllCacheKeys ¶
func (w *DataWorker) GetAllCacheKeys() ([]string, error)
func (*DataWorker) GetCacheData ¶
func (w *DataWorker) GetCacheData(obj Cacheable, key string, fields ...string) error
func (*DataWorker) GetCacheDataToMap ¶
func (*DataWorker) GetDbDriver ¶ added in v0.3.2
func (w *DataWorker) GetDbDriver() (*DbDriver, bool)
func (*DataWorker) GetInsertSql ¶ added in v0.2.14
func (w *DataWorker) GetInsertSql() string
func (*DataWorker) GetReplaceSql ¶ added in v0.2.14
func (w *DataWorker) GetReplaceSql() string
func (*DataWorker) GetSelectSql ¶ added in v0.2.14
func (w *DataWorker) GetSelectSql() string
func (*DataWorker) GetTableName ¶ added in v0.2.13
func (w *DataWorker) GetTableName() string
func (*DataWorker) GetUpdateSql ¶ added in v0.2.14
func (w *DataWorker) GetUpdateSql() string
func (*DataWorker) HasCache ¶
func (w *DataWorker) HasCache() bool
func (*DataWorker) HasDb ¶
func (w *DataWorker) HasDb() bool
func (*DataWorker) InsertToDb ¶
func (w *DataWorker) InsertToDb(mapper interface{}) (int64, error)
func (*DataWorker) InsertToDbEx ¶ added in v0.3.6
func (w *DataWorker) InsertToDbEx(mapper interface{}, extraCond string) (int64, error)
func (*DataWorker) IsOpenAutoSave ¶ added in v0.2.9
func (w *DataWorker) IsOpenAutoSave() bool
func (*DataWorker) LoadFromCache ¶
func (w *DataWorker) LoadFromCache(obj Cacheable, key string) error
func (*DataWorker) OpenAutoSave ¶ added in v0.2.9
func (w *DataWorker) OpenAutoSave()
func (*DataWorker) PreloadData ¶
func (w *DataWorker) PreloadData(obj Cacheable, mapper interface{}) error
func (*DataWorker) ReplaceToDb ¶ added in v0.2.3
func (w *DataWorker) ReplaceToDb(mapper interface{}) (int64, error)
func (*DataWorker) ReplaceToDbEx ¶ added in v0.3.6
func (w *DataWorker) ReplaceToDbEx(mapper interface{}, extraCond string) (int64, error)
func (*DataWorker) SaveCaches ¶
func (w *DataWorker) SaveCaches() error
func (*DataWorker) SelectFromDb ¶
func (w *DataWorker) SelectFromDb(mapper interface{}) (DBTableRow, error)
func (*DataWorker) SelectFromDbEx ¶ added in v0.3.6
func (w *DataWorker) SelectFromDbEx(mapper interface{}, extraCond string) (DBTableRow, error)
func (*DataWorker) SelectRowsFromDb ¶
func (w *DataWorker) SelectRowsFromDb(mapper interface{}, limitCnt int) ([]DBTableRow, error)
func (*DataWorker) SelectRowsFromDbEx ¶ added in v0.3.6
func (w *DataWorker) SelectRowsFromDbEx(mapper interface{}, extraCond string, limitCnt int) ([]DBTableRow, error)
func (*DataWorker) SetCacheData ¶
func (w *DataWorker) SetCacheData(obj Cacheable, key string, fields ...string) error
func (*DataWorker) SetCacheDataByMap ¶
func (w *DataWorker) SetCacheDataByMap(key string, mapField2Val map[string]interface{}, bMarkUpdate bool) error
func (*DataWorker) SetCacheExpire ¶
func (w *DataWorker) SetCacheExpire(key string, expiration time.Duration) error
func (*DataWorker) SetCacheSaver ¶ added in v0.3.23
func (w *DataWorker) SetCacheSaver(saver CacheSaver)
func (*DataWorker) SetCacheUpdated ¶
func (w *DataWorker) SetCacheUpdated(key string)
func (*DataWorker) SetInsertSql ¶ added in v0.3.11
func (w *DataWorker) SetInsertSql(insertSql string)
func (*DataWorker) SetReplaceSql ¶ added in v0.3.11
func (w *DataWorker) SetReplaceSql(replaceSql string)
func (*DataWorker) SetSelectSql ¶ added in v0.3.11
func (w *DataWorker) SetSelectSql(selectSql string)
func (*DataWorker) SetUpdateSql ¶ added in v0.3.11
func (w *DataWorker) SetUpdateSql(updateSql string)
func (*DataWorker) Start ¶
func (w *DataWorker) Start(saveIntv time.Duration, clearExpireIntv time.Duration)
func (*DataWorker) Stop ¶
func (w *DataWorker) Stop()
func (*DataWorker) UpdateToDb ¶
func (w *DataWorker) UpdateToDb(mapper interface{}) (int64, error)
func (*DataWorker) UpdateToDbEx ¶ added in v0.3.6
func (w *DataWorker) UpdateToDbEx(mapper interface{}, extraCond string) (int64, error)
type DbDriver ¶
type DbDriver struct {
// contains filtered or unexported fields
}
func NewDbDriver ¶
func NewDbDriver(rowObjFactory *yx.ObjectFactory) *DbDriver
func (*DbDriver) CreateTableRow ¶
func (d *DbDriver) CreateTableRow(rowReflectName string) (DBTableRow, error)
func (*DbDriver) NameInsert ¶
func (*DbDriver) NameQuery ¶
func (d *DbDriver) NameQuery(rowReflectName string, query string, mapper interface{}) ([]DBTableRow, error)
func (*DbDriver) ReuseTableRow ¶
func (d *DbDriver) ReuseTableRow(rowObj DBTableRow, rowReflectName string)
type RedisSubscribeCb ¶
type StorageConf ¶
type StorageConf struct { Cache *CacheConf `json:"cache"` Db *DBConf `json:"db"` Workers []*WorkerConf `json:"workers"` }
type WorkerConf ¶
type WorkerConf struct { // MapCacheField2DbField map[string]string `json:"field_map"` Tag string `json:"tag"` IsOpenAutoSave bool `json:"is_open_auto_save"` CacheKey string `json:"cache_key"` TableName string `json:"table_name"` RowObj string `json:"row_obj"` InsertTag string `json:"insert_tag"` SelectTag string `json:"select_tag"` SelectKeyTag string `json:"select_key_tag"` UpdateTag string `json:"update_tag"` UpdateKeyTag string `json:"update_key_tag"` }
Click to show internal directories.
Click to hide internal directories.