Documentation
¶
Index ¶
- func GetByID[k comparable, t any](ctx context.Context, loader *dataloader.Loader[k, t], id k) (t, error)
- func GetMany[k comparable, t any](ctx context.Context, loader *dataloader.Loader[k, t], ids []k) ([]t, error)
- func NewMemoryLoaderCache[K comparable, V any](ctx context.Context, cacheKey string, expiration time.Duration) dataloader.Cache[K, V]
- func WithOnDelete(cb func()) any
- type Collection
- type Conversion
- type HasKey
- type Loader
- func New[K comparable, V any](ctx context.Context, factory func(ctx context.Context, ids []K) ([]V, error), ...) *Loader[K, *V]
- func NewConversionLoader[o comparable, rt comparable](ctx context.Context, ...) *Loader[o, *rt]
- func NewCustomLoader[K comparable, V any](ctx context.Context, factory func(ctx context.Context, ids []K) ([]V, error), ...) *Loader[K, *V]
- func NewFilterLoader[K comparable](ctx context.Context, factory func(ctx context.Context, keys []K) ([]K, error), ...) *Loader[K, *K]
- func NewListLoader[K comparable, V any](ctx context.Context, factory func(ctx context.Context, ids []K) ([]V, error), ...) *Loader[K, []*V]
- func NewLoader[K comparable, V HasKey[K]](ctx context.Context, factory func(ctx context.Context, ids []K) ([]V, error), ...) *Loader[K, *V]
- func NewRelationLoader[K comparable, R comparable](ctx context.Context, ...) *Loader[R, []*K]
- type LoaderCache
- type MemoryCache
- type Option
- type Relation
- type RelationItem
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetByID ¶
func GetByID[k comparable, t any](ctx context.Context, loader *dataloader.Loader[k, t], id k) (t, error)
GetByID returns the object from the loader
func GetMany ¶
func GetMany[k comparable, t any](ctx context.Context, loader *dataloader.Loader[k, t], ids []k) ([]t, error)
GetMany retrieves multiple items from specified loader
func NewMemoryLoaderCache ¶
func NewMemoryLoaderCache[K comparable, V any](ctx context.Context, cacheKey string, expiration time.Duration) dataloader.Cache[K, V]
NewMemoryLoaderCache returns a new memory cache
func WithOnDelete ¶
func WithOnDelete(cb func()) any
WithOnDelete tells the collection to run this function when entry is deleted
Types ¶
type Collection ¶
type Collection[K comparable, V any] struct { // contains filtered or unexported fields }
Collection is a collection of loaders or other advanced structures
func NewCollection ¶
func NewCollection[K comparable, V any](expiration time.Duration) *Collection[K, V]
NewCollection of loaders or other structures
func (Collection[K, V]) Delete ¶
func (c Collection[K, V]) Delete(key K)
Delete the specified key (&entry)
func (Collection[K, V]) DeleteExpired ¶
func (c Collection[K, V]) DeleteExpired()
DeleteExpired entries
func (Collection[K, V]) Get ¶
func (c Collection[K, V]) Get(key K) (value V, ok bool)
Get a value by the specified key
func (Collection[K, V]) Set ¶
func (c Collection[K, V]) Set(key K, value V, opts ...any)
Set a key to specified value
type Conversion ¶
type Conversion[O comparable, R comparable] interface { GetOriginal() O GetResult() R }
Conversion contains the original and converted value
type HasKey ¶
type HasKey[k comparable] interface { GetKey() k }
HasKey interface for items with keys
type Loader ¶
type Loader[K comparable, V any] struct { *dataloader.Loader[K, V] }
Loader contains loader and additional functions to retrieve data easily
func New ¶
func New[K comparable, V any]( ctx context.Context, factory func(ctx context.Context, ids []K) ([]V, error), opts ...Option, ) *Loader[K, *V]
New creates a new batch loader
func NewConversionLoader ¶
func NewConversionLoader[o comparable, rt comparable]( ctx context.Context, factory func(ctx context.Context, ids []o) ([]Conversion[o, rt], error), opts ...Option, ) *Loader[o, *rt]
NewConversionLoader returns a configured batch loader for Lists
func NewCustomLoader ¶
func NewCustomLoader[K comparable, V any]( ctx context.Context, factory func(ctx context.Context, ids []K) ([]V, error), getKey func(V) K, opts ...Option, ) *Loader[K, *V]
NewCustomLoader returns a configured batch loader for items
func NewFilterLoader ¶
func NewFilterLoader[K comparable](ctx context.Context, factory func(ctx context.Context, keys []K) ([]K, error), opts ...Option) *Loader[K, *K]
NewFilterLoader is just for filtering a list of keys or checking if user has access to a specific id
func NewListLoader ¶
func NewListLoader[K comparable, V any]( ctx context.Context, factory func(ctx context.Context, ids []K) ([]V, error), getKey func(item V) K, opts ...Option, ) *Loader[K, []*V]
NewListLoader returns a configured batch loader for Lists
func NewLoader ¶
func NewLoader[K comparable, V HasKey[K]]( ctx context.Context, factory func(ctx context.Context, ids []K) ([]V, error), opts ...Option, ) *Loader[K, *V]
NewLoader returns a configured batch loader for items
func NewRelationLoader ¶
func NewRelationLoader[K comparable, R comparable]( ctx context.Context, factory func(ctx context.Context, ids []R) ([]Relation[K, R], error), opts ...Option, ) *Loader[R, []*K]
NewRelationLoader returns a configured batch loader for Lists
type LoaderCache ¶
type LoaderCache[K comparable, V any] struct { // contains filtered or unexported fields }
LoaderCache is a cache for batchloaders
func (*LoaderCache[K, V]) Delete ¶
func (c *LoaderCache[K, V]) Delete(_ context.Context, key K) bool
Delete deletes the specified key
func (*LoaderCache[K, V]) Get ¶
func (c *LoaderCache[K, V]) Get(_ context.Context, key K) (dataloader.Thunk[V], bool)
Get retrieves an entry from the cache
func (*LoaderCache[K, V]) Set ¶
func (c *LoaderCache[K, V]) Set(_ context.Context, key K, val dataloader.Thunk[V])
Set sets the specified key to value
type MemoryCache ¶
type MemoryCache struct {
// contains filtered or unexported fields
}
MemoryCache is a simple memory cache
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option is the interface for all options
func WithKeyFunc ¶
func WithKeyFunc[K comparable, V any](getKey func(V) K) Option
WithKeyFunc specifies that the key should be retrieved with this function.
func WithMemoryCache ¶
WithMemoryCache defines how long a key should live in the cache
type Relation ¶
type Relation[k comparable, kr comparable] interface { GetKey() k GetRelationID() kr }
Relation contains a simple id to relation struct
type RelationItem ¶
type RelationItem[k comparable, kr comparable] struct { Key k RelationID kr }
RelationItem implements Relation
func (RelationItem[k, kr]) GetKey ¶
func (r RelationItem[k, kr]) GetKey() k
GetKey retrieves the key for the item
func (RelationItem[k, kr]) GetRelationID ¶
func (r RelationItem[k, kr]) GetRelationID() kr
GetRelationID returns the relation ID