gormc

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is an alias of gorm.ErrRecordNotFound.
	ErrNotFound = gorm.ErrRecordNotFound
)

Functions

func Transition

func Transition(ctx context.Context, tx *gorm.DB, fc func(tx *gorm.DB) error) error

Types

type CachedConn

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

func NewConn

func NewConn(db *gorm.DB, c cache.CacheConf, opts ...cache.Option) CachedConn

NewConn returns a CachedConn with a redis cluster cache.

func NewConnWithCache

func NewConnWithCache(db *gorm.DB, c cache.Cache) CachedConn

NewConnWithCache returns a CachedConn with a custom cache.

func NewNodeConn

func NewNodeConn(db *gorm.DB, rds *redis.Redis, opts ...cache.Option) CachedConn

NewNodeConn returns a CachedConn with a redis node cache.

func (CachedConn) DelCache

func (cc CachedConn) DelCache(keys ...string) error

DelCache deletes cache with keys.

func (CachedConn) DelCacheCtx

func (cc CachedConn) DelCacheCtx(ctx context.Context, keys ...string) error

DelCacheCtx deletes cache with keys.

func (CachedConn) Exec

func (cc CachedConn) Exec(exec ExecCtxFn, keys ...string) error

Exec runs given exec on given keys, and returns execution result.

func (CachedConn) ExecCtx

func (cc CachedConn) ExecCtx(ctx context.Context, execCtx ExecCtxFn, keys ...string) error

ExecCtx runs given exec on given keys, and returns execution result.

func (CachedConn) ExecNoCache

func (cc CachedConn) ExecNoCache(exec ExecCtxFn) error

ExecNoCache runs exec with given sql statement, without affecting cache.

func (CachedConn) ExecNoCacheCtx

func (cc CachedConn) ExecNoCacheCtx(ctx context.Context, execCtx ExecCtxFn) (err error)

ExecNoCacheCtx runs exec with given sql statement, without affecting cache.

func (CachedConn) GetCache

func (cc CachedConn) GetCache(key string, v any) error

GetCache unmarshals cache with given key into v.

func (CachedConn) GetCacheCtx

func (cc CachedConn) GetCacheCtx(ctx context.Context, key string, v any) error

GetCacheCtx unmarshals cache with given key into v.

func (CachedConn) QueryCtx

func (cc CachedConn) QueryCtx(ctx context.Context, v any, key string, query QueryCtxFn) (err error)

func (CachedConn) QueryNoCacheCtx

func (cc CachedConn) QueryNoCacheCtx(ctx context.Context, v any, query QueryCtxFn) (err error)

func (CachedConn) QueryRowIndex

func (cc CachedConn) QueryRowIndex(v any, key string, keyer func(primary any) string,
	indexQuery IndexQueryCtxFn, primaryQuery PrimaryQueryCtxFn) error

QueryRowIndex unmarshals into v with given key.

func (CachedConn) QueryRowIndexCtx

func (cc CachedConn) QueryRowIndexCtx(ctx context.Context, v any, key string, keyer func(primary any) string, indexQuery IndexQueryCtxFn, primaryQuery PrimaryQueryCtxFn) (err error)

QueryRowIndexCtx unmarshals into v with given key.

func (CachedConn) QueryWithExpireCtx

func (cc CachedConn) QueryWithExpireCtx(ctx context.Context, v any, key string, expire time.Duration, query QueryCtxFn) (err error)

QueryWithExpireCtx unmarshals into v with given key, set expire duration and query func.

func (CachedConn) SetCache

func (cc CachedConn) SetCache(key string, v any) error

SetCache sets v into cache with given key.

func (CachedConn) SetCacheCtx

func (cc CachedConn) SetCacheCtx(ctx context.Context, key string, val any) error

SetCacheCtx sets v into cache with given key.

func (CachedConn) SetCacheWithExpireCtx

func (cc CachedConn) SetCacheWithExpireCtx(ctx context.Context, key string, val any, expire time.Duration) error

SetCacheWithExpireCtx sets v into cache with given key.

func (CachedConn) WithSession

func (cc CachedConn) WithSession(tx *gorm.DB) CachedConn

WithSession replace the db to new *gorm.DB instance

type ExecCtxFn

type ExecCtxFn func(conn *gorm.DB) error

ExecCtxFn defines the sql exec method.

type GormLog

type GormLog struct {
	Level                     logger.LogLevel
	IgnoreRecordNotFoundError bool
	SlowThreshold             time.Duration
}

func (*GormLog) Error

func (g *GormLog) Error(ctx context.Context, format string, data ...any)

func (*GormLog) Info

func (g *GormLog) Info(ctx context.Context, format string, data ...any)

func (*GormLog) LogMode

func (g *GormLog) LogMode(level logger.LogLevel) logger.Interface

func (*GormLog) Trace

func (g *GormLog) Trace(ctx context.Context, begin time.Time, fc func() (sql string, rowsAffected int64), err error)

func (*GormLog) Warn

func (g *GormLog) Warn(ctx context.Context, format string, data ...any)

type IndexQueryCtxFn

type IndexQueryCtxFn func(conn *gorm.DB, v any) (any, error)

IndexQueryCtxFn defines the query method that based on unique indexes.

type MetricsPlugin

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

func (*MetricsPlugin) After

func (o *MetricsPlugin) After(db *gorm.DB)

func (*MetricsPlugin) Before

func (o *MetricsPlugin) Before(db *gorm.DB)

func (*MetricsPlugin) Initialize

func (o *MetricsPlugin) Initialize(db *gorm.DB) (err error)

func (*MetricsPlugin) Name

func (o *MetricsPlugin) Name() string

type OtelPlugin

type OtelPlugin struct {
}

func (OtelPlugin) After

func (o OtelPlugin) After(db *gorm.DB)

func (OtelPlugin) Before

func (o OtelPlugin) Before(spanName string) func(db *gorm.DB)

func (OtelPlugin) Initialize

func (o OtelPlugin) Initialize(db *gorm.DB) (err error)

func (OtelPlugin) Name

func (o OtelPlugin) Name() string

type PrimaryQueryCtxFn

type PrimaryQueryCtxFn func(conn *gorm.DB, v, primary any) error

PrimaryQueryCtxFn defines the query method that based on primary keys.

type QueryCtxFn

type QueryCtxFn func(conn *gorm.DB, v any) error

QueryCtxFn defines the query method.

Directories

Path Synopsis
pg

Jump to

Keyboard shortcuts

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