mongo

package
v0.0.0-...-da57006 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2019 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound = mgo.ErrNotFound
	NewObjectId = bson.NewObjectId
)
View Source
var ErrCacheIsNil = errors.New("*DB.Cache (redis) is nil")

ErrCacheIsNil db cache(redis) is nil

Functions

This section is empty.

Types

type CacheDB

type CacheDB struct {
	*DB
	// contains filtered or unexported fields
}

CacheDB cache DB handle

func (*CacheDB) CreateCacheKey

func (c *CacheDB) CreateCacheKey(structPtr Cacheable, fields ...string) (CacheKey, error)

CreateCacheKey

func (*CacheDB) CreateCacheKeyByFields

func (c *CacheDB) CreateCacheKeyByFields(fields []string, values []interface{}) (string, error)

CreateCacheKeyByFields

func (*CacheDB) CreateGetQuery

func (c *CacheDB) CreateGetQuery(values []interface{}, whereConds ...string) bson.M

CreateGetQuery

func (*CacheDB) GetCache

func (c *CacheDB) GetCache(destStructPtr Cacheable, fields ...string) error

GetCache

func (*CacheDB) WitchCollection

func (c *CacheDB) WitchCollection(s func(*mgo.Collection) error) error

WitchCollection

type CacheKey

type CacheKey struct {
	Key    string
	Values []interface{}
	// contains filtered or unexported fields
}

CacheKey cache key info

type Cacheable

type Cacheable interface {
	TableName() string
}

Cacheable

type Config

type Config struct {
	// Addrs host
	Addrs []string `yaml:"addr"`
	// Timeout
	Timeout time.Duration `yaml:"timeout"`
	// Database mgo db name
	Database string `yaml:"database"`
	// Username
	Username string `yaml:"username"`
	// Password
	Password string `yaml:"passward"`
	// PoolLimit
	PoolLimit int `yaml:"pool_limit"`
	// CloseCache default open cache
	CloseCache bool `yaml:"close_cache"`
}

Config mongodb config

func NewConfig

func NewConfig() *Config

NewConfig

func (*Config) Source

func (mgoConfig *Config) Source() *mgo.DialInfo

Source

type DB

type DB struct {
	*mgo.Session
	Cache *redis.Client
	// contains filtered or unexported fields
}

DB mongodb db info

func (*DB) GetCacheDB

func (d *DB) GetCacheDB(tableName string) (*CacheDB, error)

GetCacheDB get cacheDB

func (*DB) RegisterCacheDB

func (d *DB) RegisterCacheDB(structPtr Cacheable, cacheExpire time.Duration) (*CacheDB, error)

RegisterCacheDB register cache db

type PreDB

type PreDB struct {
	*DB
	// contains filtered or unexported fields
}

PreDB preset *DB

func NewPreDB

func NewPreDB() *PreDB

NewPreDB

func (*PreDB) Init

func (p *PreDB) Init(dbConfig *Config, redisConfig *redis.Config) (err error)

func (*PreDB) InitByCache

func (p *PreDB) InitByCache(dbConfig *Config, redisClient *redis.Client) (err error)

InitByCache

func (*PreDB) RegisterCacheableDB

func (p *PreDB) RegisterCacheableDB(ormStructPtr Cacheable, cacheExpire time.Duration) (*CacheDB, error)

RegisterCacheableDB

Jump to

Keyboard shortcuts

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