dbloader

package
v0.0.0-...-bc49051 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Batch

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

func (*Batch[K, V]) Keys

func (b *Batch[K, V]) Keys() (output []K)

Keys returns the "scheduled" keys to be fetched.

func (*Batch[K, V]) Load

func (b *Batch[K, V]) Load(k K) *V

Load returns a promise to load a value with a given key.

func (*Batch[K, V]) Resolve

func (b *Batch[K, V]) Resolve(ctx context.Context) error

Resolve resoles the "promises" for the values for given keys and makes the stored pointers point at valid targets.

type Loader

type Loader[K comparable, V any] struct {
	Resolver func(context.Context, ...K) (map[K]V, error)
}

Loader is a specific "batch" of calls to the loader resolver.

func LoaderFor

func LoaderFor[K comparable, V any](dbc *db.Connection, opts ...db.InvocationOption) Loader[K, V]

LoaderFor returns a loader for a given type.

Specifically it uses a `GetMany` command on the dbc to fetch the keys for a given batch.

There are very specific constraints on the types we can use as the values here, specifically the types can only have (1) primary key, and the key values will be resolved with reflection incurring a bit of a performance hit.

func (Loader[K, V]) New

func (l Loader[K, V]) New() *Batch[K, V]

Jump to

Keyboard shortcuts

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