dbcache

package
v0.0.0-...-a2366b1 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(debug ...bool)

func NewLocalCache

func NewLocalCache() *localCache

func NewRedisCache

func NewRedisCache() *redisCache

func RedisCacheInit

func RedisCacheInit(host, port, auth string, module ...string)

func RegisterCache

func RegisterCache(c Cache)

RegisterCache 缓存注册

func SETExpire

func SETExpire(e int)

func SetDebug

func SetDebug(debug ...bool)

Types

type Cache

type Cache interface {
	Set(key, value string, expire ...int) bool
	Get(key string) string
	Expire(key string, expire int) int
	Del(key string) int
}

type Dao

type Dao struct {
	// contains filtered or unexported fields
}

func NewDb

func NewDb(dbname ...string) *Dao

func (*Dao) ClearCache

func (d *Dao) ClearCache()

func (*Dao) Create

func (d *Dao) Create(data interface{}) (int64, error)

func (*Dao) DB

func (d *Dao) DB() *gorm.DB

func (*Dao) DryRun

func (d *Dao) DryRun() *gorm.DB

func (*Dao) EXEC

func (d *Dao) EXEC() (int64, error)

func (*Dao) Fetch

func (d *Dao) Fetch(result interface{}) error
Example
db := NewDb()
var user1 User
db.DB().AutoMigrate(&User{})
stmt := db.DryRun().Find(&user1, 1).Statement
tag := "users000"
err := db.SetTag(tag).PrepareSql(stmt.SQL.String(), stmt.Vars...).Fetch(&user1)
fmt.Println(user1.Id, err)

var users []User
// 会话模式
stmt = db.DryRun().Find(&users).Statement
db.SetTag(tag).PrepareSql(stmt.SQL.String(), stmt.Vars...).Fetch(&users)
fmt.Println("result", len(users) > 0)
Output:

	1 <nil>
result true

func (*Dao) PrepareSql

func (d *Dao) PrepareSql(sql string, params ...interface{}) Daoer

func (*Dao) SetKey

func (d *Dao) SetKey(key string) Daoer

func (*Dao) SetTag

func (d *Dao) SetTag(tag string) Daoer

type Daoer

type Daoer interface {
	DB() *gorm.DB
	DryRun() *gorm.DB
	SetTag(tag string) Daoer
	SetKey(key string) Daoer
	PrepareSql(sql string, params ...interface{}) Daoer
	Fetch(result interface{}) error
	EXEC() (int64, error)
	Create(data interface{}) (int64, error)
	ClearCache()
}

Jump to

Keyboard shortcuts

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