Documentation ¶
Index ¶
- func Get[T any](ctx context.Context, db sqlx.QueryerContext, query string, args ...any) (T, error)
- func LazyGet[T any](db sqlx.QueryerContext, query string, args ...any) func(ctx context.Context) (T, error)
- func LazyList[T any](db sqlx.QueryerContext, query string, args ...any) func(ctx context.Context) ([]T, error)
- func List[T any](ctx context.Context, db sqlx.QueryerContext, query string, args ...any) ([]T, error)
- type Cache
- type Iterator
- type Selector
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LazyGet ¶
func LazyGet[T any](db sqlx.QueryerContext, query string, args ...any) func(ctx context.Context) (T, error)
LazyGet generates closure which wraps prepared query with arguments and executes query with single result on-demand. The function doesn't cache anything, use Cache for lazy cached queries.
Types ¶
type Cache ¶
type Cache[T any] struct { // contains filtered or unexported fields }
Cache stores data and factory to get data.
func CachedGet ¶
CachedGet is alias of NewCache(LazyGet) and provides cached information from database.
func CachedList ¶
CachedList is alias of NewCache(LazyList) and provides cached information from database.
func (*Cache[T]) Get ¶
Get content from cache or from storage. Once data fetched, it will be stored internally.
func (*Cache[T]) Invalidate ¶
func (ct *Cache[T]) Invalidate()
Invalidate cache and cause refresh on next Cache.Get operation.
type Iterator ¶
type Iterator[T any] struct { // contains filtered or unexported fields }
Iterator is typed wrapper around sql.Rows which is automatically scans row to the provided type.
func Iterate ¶
func Iterate[T any](ctx context.Context, db sqlx.QueryerContext, query string, args ...any) *Iterator[T]
Iterate over multiple results and automatically scans each row to the provided type.
func Rows ¶
Rows is a simple wrapper around sqlx.Rows which is automatically scans row to the provided type.