loaders

package
v0.0.0-...-8eba3d0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

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]) Keys

func (c Collection[K, V]) Keys() []K

Keys returns all keys

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

func (*Loader[K, V]) Get

func (bl *Loader[K, V]) Get(ctx context.Context, key K) (V, error)

Get retrieves a specific entry from the loader

func (*Loader[K, V]) GetMany

func (bl *Loader[K, V]) GetMany(ctx context.Context, keys []K) ([]V, error)

GetMany retrieves the specified entries from the loader

type LoaderCache

type LoaderCache[K comparable, V any] struct {
	// contains filtered or unexported fields
}

LoaderCache is a cache for batchloaders

func (*LoaderCache[K, V]) Clear

func (c *LoaderCache[K, V]) Clear()

Clear clears the entire cache

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

func WithMemoryCache(expiration time.Duration) Option

WithMemoryCache defines how long a key should live in the cache

func WithName

func WithName(name string) Option

WithName assigns the specified name to the tracer

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

Jump to

Keyboard shortcuts

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