dataloader

package
v1.0.13 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	ProfessionRepo    profession.Repository
	QualificationRepo qualification.Repository
}

type DataLoader

type DataLoader struct {
	QualificationByID            *QualificationLoader
	QualificationsByProfessionID *QualificationSliceByProfessionIDLoader
}

func New

func New(cfg Config) *DataLoader

type QualificationLoader

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

QualificationLoader batches and caches requests

func NewQualificationLoader

func NewQualificationLoader(config QualificationLoaderConfig) *QualificationLoader

NewQualificationLoader creates a new QualificationLoader given a fetch, wait, and maxBatch

func (*QualificationLoader) Clear

func (l *QualificationLoader) Clear(key int)

Clear the value at key from the cache, if it exists

func (*QualificationLoader) Load

func (l *QualificationLoader) Load(key int) (*model.Qualification, error)

Load a Qualification by key, batching and caching will be applied automatically

func (*QualificationLoader) LoadAll

func (l *QualificationLoader) LoadAll(keys []int) ([]*model.Qualification, []error)

LoadAll fetches many keys at once. It will be broken into appropriate sized sub batches depending on how the loader is configured

func (*QualificationLoader) LoadAllThunk

func (l *QualificationLoader) LoadAllThunk(keys []int) func() ([]*model.Qualification, []error)

LoadAllThunk returns a function that when called will block waiting for a Qualifications. This method should be used if you want one goroutine to make requests to many different data loaders without blocking until the thunk is called.

func (*QualificationLoader) LoadThunk

func (l *QualificationLoader) LoadThunk(key int) func() (*model.Qualification, error)

LoadThunk returns a function that when called will block waiting for a Qualification. This method should be used if you want one goroutine to make requests to many different data loaders without blocking until the thunk is called.

func (*QualificationLoader) Prime

func (l *QualificationLoader) Prime(key int, value *model.Qualification) bool

Prime the cache with the provided key and value. If the key already exists, no change is made and false is returned. (To forcefully prime the cache, clear the key first with loader.clear(key).prime(key, value).)

type QualificationLoaderConfig

type QualificationLoaderConfig struct {
	// Fetch is a method that provides the data for the loader
	Fetch func(keys []int) ([]*model.Qualification, []error)

	// Wait is how long wait before sending a batch
	Wait time.Duration

	// MaxBatch will limit the maximum number of keys to send in one batch, 0 = not limit
	MaxBatch int
}

QualificationLoaderConfig captures the config to create a new QualificationLoader

type QualificationSliceByProfessionIDLoader

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

QualificationSliceByProfessionIDLoader batches and caches requests

func NewQualificationSliceByProfessionIDLoader

func NewQualificationSliceByProfessionIDLoader(config QualificationSliceByProfessionIDLoaderConfig) *QualificationSliceByProfessionIDLoader

NewQualificationSliceByProfessionIDLoader creates a new QualificationSliceByProfessionIDLoader given a fetch, wait, and maxBatch

func (*QualificationSliceByProfessionIDLoader) Clear

Clear the value at key from the cache, if it exists

func (*QualificationSliceByProfessionIDLoader) Load

Load a Qualification by key, batching and caching will be applied automatically

func (*QualificationSliceByProfessionIDLoader) LoadAll

LoadAll fetches many keys at once. It will be broken into appropriate sized sub batches depending on how the loader is configured

func (*QualificationSliceByProfessionIDLoader) LoadAllThunk

func (l *QualificationSliceByProfessionIDLoader) LoadAllThunk(keys []int) func() ([][]*model.Qualification, []error)

LoadAllThunk returns a function that when called will block waiting for a Qualifications. This method should be used if you want one goroutine to make requests to many different data loaders without blocking until the thunk is called.

func (*QualificationSliceByProfessionIDLoader) LoadThunk

func (l *QualificationSliceByProfessionIDLoader) LoadThunk(key int) func() ([]*model.Qualification, error)

LoadThunk returns a function that when called will block waiting for a Qualification. This method should be used if you want one goroutine to make requests to many different data loaders without blocking until the thunk is called.

func (*QualificationSliceByProfessionIDLoader) Prime

Prime the cache with the provided key and value. If the key already exists, no change is made and false is returned. (To forcefully prime the cache, clear the key first with loader.clear(key).prime(key, value).)

type QualificationSliceByProfessionIDLoaderConfig

type QualificationSliceByProfessionIDLoaderConfig struct {
	// Fetch is a method that provides the data for the loader
	Fetch func(keys []int) ([][]*model.Qualification, []error)

	// Wait is how long wait before sending a batch
	Wait time.Duration

	// MaxBatch will limit the maximum number of keys to send in one batch, 0 = not limit
	MaxBatch int
}

QualificationSliceByProfessionIDLoaderConfig captures the config to create a new QualificationSliceByProfessionIDLoader

Jump to

Keyboard shortcuts

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