orm

package
v0.0.0-...-b5fa30d Latest Latest
Warning

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

Go to latest
Published: May 29, 2019 License: MIT Imports: 9 Imported by: 1

README

ORM支持部分查询缓存

  • 查询缓存接口
    • First()
    • Last()
    • Find()
    • Count()

使用Cache(db)做查询支持缓存

user := User{}
var count int64
db := DB().Where("id = ?", id)

// 连续查询均支持缓存
db := Cache(db).First(&user).Count(&count)  // *CacheDB

// 如果要取消缓存,中间插入.DB
db := Cache(db).First(&user).DB.Count(&count)   // *gorm.DB

ORM层OpenTracing支持 示例

// 将Request context传入Model
u := model.User{
    Model: orm.Model{Context: c},
}

// ORM查询时启动Trace
if s := u.Trace(); s != nil {
    defer s.Finish()
}

Documentation

Index

Constants

View Source
const (
	CacheExpireDefault = time.Minute
	CacheKeyFormat     = "SQL:%s SQLVars:%v"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheConf

type CacheConf struct {
	Expire time.Duration
}

type CacheDB

type CacheDB struct {
	*gorm.DB

	Expire time.Duration
	// contains filtered or unexported fields
}

func NewCacheDB

func NewCacheDB(db *gorm.DB, store cache.CacheStore, conf CacheConf) *CacheDB

func (*CacheDB) Count

func (c *CacheDB) Count(out interface{}) *CacheDB

func (*CacheDB) Find

func (c *CacheDB) Find(out interface{}, where ...interface{}) *CacheDB

func (*CacheDB) First

func (c *CacheDB) First(out interface{}, where ...interface{}) *CacheDB

func (*CacheDB) Last

func (c *CacheDB) Last(out interface{}, where ...interface{}) *CacheDB

type Logger

type Logger struct {
}

func (Logger) Print

func (logger Logger) Print(values ...interface{})

Print format & print log

type Model

type Model struct {
	Context context
}

func (Model) Trace

func (m Model) Trace() opentracing.Span

Jump to

Keyboard shortcuts

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