entity

package
v0.24.6 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound 数据未找到
	ErrNotFound = errors.New("data not found")
	// ErrEmptyPlaceholder 数据为空
	ErrEmptyPlaceholder = errors.New("empty placeholder")
	// ErrTimeout 超时
	ErrTimeout = errors.New("timeout")
)

Functions

This section is empty.

Types

type EntityManager

type EntityManager interface {
	// Get 根据主键获取数据
	Get(id uint64, out interface{}) error

	// GetWithQuery 根据主键获取数据
	GetWithQuery(id uint64, query QueryHandler, out interface{}) error

	// List 列出 key 对应的数据
	List(key string, query QueryHandler, out interface{}) error

	// Update 更新
	Update(id uint64, in interface{}) error

	// Delete 删除
	Delete(id uint64, model interface{}) error

	// SetTimeout 设置超时时间
	SetTimeout(timeout time.Duration)
}

EntityManager 实体管理器

func NewManager

func NewManager(db WrapDB, cache WrapCache, st *Stat, logger zerologger.Logger, codec zerocodec.Codec) EntityManager

NewManager 创建一个实体管理器

type QueryHandler

type QueryHandler func(id uint64, out interface{}) error

QueryHandler 查询函数

type Stat

type Stat struct {
	Name string

	// QueryHit 查询缓存命中次数
	QueryHit uint64
	// QueryMiss 查询缓存未命中次数
	QueryMiss uint64

	// DBFails 数据库查询失败次数
	DBFails uint64
	// contains filtered or unexported fields
}

Stat 统计

func NewStat

func NewStat(name string, logger zerologger.Logger) *Stat

func (*Stat) IncrementDBFails

func (st *Stat) IncrementDBFails()

IncrementDbFails 增加数据库查询失败次数

func (*Stat) IncrementQueryHit

func (st *Stat) IncrementQueryHit()

IncrementQueryHit 增加查询缓存命中次数

func (*Stat) IncrementQueryMiss

func (st *Stat) IncrementQueryMiss()

IncrementQueryMiss 增加查询未命中次数

type WrapCache

type WrapCache interface {
	Get(key string) ([]byte, error)
	Set(key string, in []byte) error
	Delete(key string) error
	ErrNotFound() error
}

WrapCache 封装缓存

func NewWrapCache

func NewWrapCache(eviction time.Duration) WrapCache

NewWrapCache .. eviction 过期时间

type WrapDB

type WrapDB interface {
	Get(id uint64, out interface{}) error
	Update(in interface{}) error
	Delete(id uint64, model interface{}) error
	ErrNotFound() error
}

WrapDB 封装数据库

func NewWrapDB

func NewWrapDB(db zerodatabase.Database) WrapDB

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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