sqlc

package
v0.0.0-...-9b66df9 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

Functions

This section is empty.

Types

type CachedConn

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

A CachedConn is a DB connection with cache capability.

func NewConn

func NewConn(db sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) CachedConn

NewConn returns a CachedConn with a redis cluster cache.

func NewConnWithCache

func NewConnWithCache(db sqlx.SqlConn, c cache.Cache) CachedConn

NewConnWithCache returns a CachedConn with a custom cache.

func NewNodeConn

func NewNodeConn(db sqlx.SqlConn, 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 ExecFn, keys ...string) (sql.Result, error)

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

func (CachedConn) ExecCtx

func (cc CachedConn) ExecCtx(ctx context.Context, exec ExecCtxFn, keys ...string) (
	sql.Result, error)

ExecCtx runs given exec on given keys, and returns execution result. If DB operation succeeds, it will delete cache with given keys, if DB operation fails, it will return nil result and non-nil error, if DB operation succeeds but cache deletion fails, it will return result and non-nil error.

func (CachedConn) ExecNoCache

func (cc CachedConn) ExecNoCache(q string, args ...any) (sql.Result, error)

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

func (CachedConn) ExecNoCacheCtx

func (cc CachedConn) ExecNoCacheCtx(ctx context.Context, q string, args ...any) (
	sql.Result, 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) QueryRow

func (cc CachedConn) QueryRow(v any, key string, query QueryFn) error

QueryRow unmarshals into v with given key and query func.

func (CachedConn) QueryRowCtx

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

QueryRowCtx unmarshals into v with given key and query func.

func (CachedConn) QueryRowIndex

func (cc CachedConn) QueryRowIndex(v any, key string, keyer func(primary any) string,
	indexQuery IndexQueryFn, primaryQuery PrimaryQueryFn) 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) error

QueryRowIndexCtx unmarshals into v with given key.

func (CachedConn) QueryRowNoCache

func (cc CachedConn) QueryRowNoCache(v any, q string, args ...any) error

QueryRowNoCache unmarshals into v with given statement.

func (CachedConn) QueryRowNoCacheCtx

func (cc CachedConn) QueryRowNoCacheCtx(ctx context.Context, v any, q string,
	args ...any) error

QueryRowNoCacheCtx unmarshals into v with given statement.

func (CachedConn) QueryRowsNoCache

func (cc CachedConn) QueryRowsNoCache(v any, q string, args ...any) error

QueryRowsNoCache unmarshals into v with given statement. It doesn't use cache, because it might cause consistency problem.

func (CachedConn) QueryRowsNoCacheCtx

func (cc CachedConn) QueryRowsNoCacheCtx(ctx context.Context, v any, q string,
	args ...any) error

QueryRowsNoCacheCtx unmarshals into v with given statement. It doesn't use cache, because it might cause consistency problem.

func (CachedConn) SetCache

func (cc CachedConn) SetCache(key string, val 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) SetCacheWithExpire

func (cc CachedConn) SetCacheWithExpire(key string, val any, expire time.Duration) error

SetCacheWithExpire sets v into cache with given key with given expire.

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 with given expire.

func (CachedConn) Transact

func (cc CachedConn) Transact(fn func(sqlx.Session) error) error

Transact runs given fn in transaction mode.

func (CachedConn) TransactCtx

func (cc CachedConn) TransactCtx(ctx context.Context, fn func(context.Context, sqlx.Session) error) error

TransactCtx runs given fn in transaction mode.

func (CachedConn) WithSession

func (cc CachedConn) WithSession(session sqlx.Session) CachedConn

WithSession returns a new CachedConn with given session. If query from session, the uncommitted data might be returned. Don't query for the uncommitted data, you should just use it, and don't use the cache for the uncommitted data. Not recommend to use cache within transactions due to consistency problem.

type ExecCtxFn

type ExecCtxFn func(ctx context.Context, conn sqlx.SqlConn) (sql.Result, error)

ExecCtxFn defines the sql exec method.

type ExecFn

type ExecFn func(conn sqlx.SqlConn) (sql.Result, error)

ExecFn defines the sql exec method.

type IndexQueryCtxFn

type IndexQueryCtxFn func(ctx context.Context, conn sqlx.SqlConn, v any) (any, error)

IndexQueryCtxFn defines the query method that based on unique indexes.

type IndexQueryFn

type IndexQueryFn func(conn sqlx.SqlConn, v any) (any, error)

IndexQueryFn defines the query method that based on unique indexes.

type PrimaryQueryCtxFn

type PrimaryQueryCtxFn func(ctx context.Context, conn sqlx.SqlConn, v, primary any) error

PrimaryQueryCtxFn defines the query method that based on primary keys.

type PrimaryQueryFn

type PrimaryQueryFn func(conn sqlx.SqlConn, v, primary any) error

PrimaryQueryFn defines the query method that based on primary keys.

type QueryCtxFn

type QueryCtxFn func(ctx context.Context, conn sqlx.SqlConn, v any) error

QueryCtxFn defines the query method.

type QueryFn

type QueryFn func(conn sqlx.SqlConn, v any) error

QueryFn defines the query method.

Jump to

Keyboard shortcuts

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