Documentation ¶
Index ¶
- Variables
- type CacheKey
- type Cacheable
- type CacheableDB
- func (c *CacheableDB) CacheGet(destStructPtr Cacheable, fields ...string) error
- func (c *CacheableDB) CreateCacheKey(structPtr Cacheable, fields ...string) (CacheKey, error)
- func (c *CacheableDB) CreateCacheKeyByFields(fields []string, values []interface{}) (string, error)
- func (c *CacheableDB) CreateGetQuery(values []interface{}, whereFields ...string) M
- func (c *CacheableDB) DeleteCache(srcStructPtr Cacheable, fields ...string) error
- func (c *CacheableDB) PutCache(srcStructPtr Cacheable, fields ...string) error
- func (c *CacheableDB) WitchCollection(s func(*Collection) error) error
- type Collection
- type Config
- type DB
- type M
- type ObjectId
- type PreDB
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotFound = mgo.ErrNotFound NewObjectId = bson.NewObjectId )
var ErrCacheNil = errors.New("*DB.Cache (redis) is nil")
ErrCacheNil error: *DB.Cache (redis) is nil
Functions ¶
This section is empty.
Types ¶
type CacheKey ¶
type CacheKey struct { Key string FieldValues []interface{} // contains filtered or unexported fields }
CacheKey cache key and values corresponding to primary keys
type Cacheable ¶
type Cacheable interface {
TableName() string
}
Cacheable the interface that can use cache. It must be orm-struct.
type CacheableDB ¶
type CacheableDB struct { *DB // contains filtered or unexported fields }
CacheableDB cacheable DB handle
func (*CacheableDB) CacheGet ¶
func (c *CacheableDB) CacheGet(destStructPtr Cacheable, fields ...string) error
CacheGet selects one row by primary key. Priority from the read cache. Note:
If the cache does not exist, then write the cache; @destStructPtr must be a *struct type; If fields is empty, auto-use primary fields.
func (*CacheableDB) CreateCacheKey ¶
func (c *CacheableDB) CreateCacheKey(structPtr Cacheable, fields ...string) (CacheKey, error)
CreateCacheKey creates cache key and fields' values. Note: if fields is empty, auto-use primary fields.
func (*CacheableDB) CreateCacheKeyByFields ¶
func (c *CacheableDB) CreateCacheKeyByFields(fields []string, values []interface{}) (string, error)
CreateCacheKeyByFields creates the cache key string by specified fields and values.
func (*CacheableDB) CreateGetQuery ¶
func (c *CacheableDB) CreateGetQuery(values []interface{}, whereFields ...string) M
func (*CacheableDB) DeleteCache ¶
func (c *CacheableDB) DeleteCache(srcStructPtr Cacheable, fields ...string) error
DeleteCache deletes one row form cache by primary key. Note:
@destStructPtr must be a *struct type; If fields is empty, auto-use primary fields.
func (*CacheableDB) PutCache ¶
func (c *CacheableDB) PutCache(srcStructPtr Cacheable, fields ...string) error
PutCache caches one row by primary key. Note:
@destStructPtr must be a *struct type; If fields is empty, auto-use primary fields.
func (*CacheableDB) WitchCollection ¶
func (c *CacheableDB) WitchCollection(s func(*Collection) error) error
Common method
type Collection ¶
type Collection = mgo.Collection
type Config ¶
type Config struct { Addrs []string `yaml:"addrs"` Timeout time.Duration `yaml:"timeout"` Database string `yaml:"database"` // Username and Password inform the credentials for the initial authentication // done on the database defined by the Source field. See Session.Login. Username string `yaml:"username"` Password string `yaml:"passward"` // PoolLimit defines the per-server socket pool limit. Defaults to 4096. // See Session.SetPoolLimit for details. PoolLimit int `yaml:"pool_limit"` // NoCache whether to disable cache NoCache bool `yaml:"no_cache"` // contains filtered or unexported fields }
Config mongodb setting
func ReadConfig ¶
ReadConfig gets a mongodb db config form yaml.
type DB ¶
DB is a wrapper around sqlx.DB and redis.Client.
func (*DB) GetCacheableDB ¶
func (d *DB) GetCacheableDB(tableName string) (*CacheableDB, error)
GetCacheableDB returns the specified *CacheableDB
func (*DB) RegCacheableDB ¶
func (d *DB) RegCacheableDB(ormStructPtr Cacheable, cacheExpiration time.Duration) (*CacheableDB, error)
RegCacheableDB registers a cacheable table.
type PreDB ¶
type PreDB struct { *DB // contains filtered or unexported fields }
PreDB preset *DB
func (*PreDB) RegCacheableDB ¶
func (p *PreDB) RegCacheableDB(ormStructPtr Cacheable, cacheExpiration time.Duration) (*CacheableDB, error)
RegCacheableDB registers a cacheable table.