dataloaders

package
v1.0.1-0...-4418604 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

README

  1. Get the generator go get github.com/vektah/dataloaden
  2. Run the generation like dataloaden UserLoader string *github.com/VertaAI/modeldb-go/protos/private/uac.UserInfo in the same directory as models_gen.go
  3. Move the generated files to dataloaders and adjust any imports
  4. Add a constructor method as described in https://github.com/vektah/dataloaden
  5. Use as described in https://gqlgen.com/reference/dataloaders/

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetTeamById

func GetTeamById(ctx context.Context, id string) (*uac.Team, error)

func GetUserById

func GetUserById(ctx context.Context, id string) (*ai_verta_uac.UserInfo, error)

func TeamDataloaderMiddleware

func TeamDataloaderMiddleware(conn *connections.Connections) func(httprouter.Handle) httprouter.Handle

func UserDataloaderMiddleware

func UserDataloaderMiddleware(conn *connections.Connections) func(httprouter.Handle) httprouter.Handle

Types

type TeamLoader

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

TeamLoader batches and caches requests

func NewTeamLoader

func NewTeamLoader(config TeamLoaderConfig) *TeamLoader

NewTeamLoader creates a new TeamLoader given a fetch, wait, and maxBatch

func (*TeamLoader) Clear

func (l *TeamLoader) Clear(key string)

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

func (*TeamLoader) Load

func (l *TeamLoader) Load(key string) (*uac.Team, error)

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

func (*TeamLoader) LoadAll

func (l *TeamLoader) LoadAll(keys []string) ([]*uac.Team, []error)

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

func (*TeamLoader) LoadAllThunk

func (l *TeamLoader) LoadAllThunk(keys []string) func() ([]*uac.Team, []error)

LoadAllThunk returns a function that when called will block waiting for a Teams. 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 (*TeamLoader) LoadThunk

func (l *TeamLoader) LoadThunk(key string) func() (*uac.Team, error)

LoadThunk returns a function that when called will block waiting for a Team. 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 (*TeamLoader) Prime

func (l *TeamLoader) Prime(key string, value *uac.Team) 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 TeamLoaderConfig

type TeamLoaderConfig struct {
	// Fetch is a method that provides the data for the loader
	Fetch func(keys []string) ([]*uac.Team, []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
}

TeamLoaderConfig captures the config to create a new TeamLoader

type UserLoader

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

UserLoader batches and caches requests

func NewUserLoader

func NewUserLoader(config UserLoaderConfig) *UserLoader

NewUserLoader creates a new UserLoader given a fetch, wait, and maxBatch

func (*UserLoader) Clear

func (l *UserLoader) Clear(key string)

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

func (*UserLoader) Load

func (l *UserLoader) Load(key string) (*uac.UserInfo, error)

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

func (*UserLoader) LoadAll

func (l *UserLoader) LoadAll(keys []string) ([]*uac.UserInfo, []error)

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

func (*UserLoader) LoadAllThunk

func (l *UserLoader) LoadAllThunk(keys []string) func() ([]*uac.UserInfo, []error)

LoadAllThunk returns a function that when called will block waiting for a UserInfos. 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 (*UserLoader) LoadThunk

func (l *UserLoader) LoadThunk(key string) func() (*uac.UserInfo, error)

LoadThunk returns a function that when called will block waiting for a UserInfo. 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 (*UserLoader) Prime

func (l *UserLoader) Prime(key string, value *uac.UserInfo) 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 UserLoaderConfig

type UserLoaderConfig struct {
	// Fetch is a method that provides the data for the loader
	Fetch func(keys []string) ([]*uac.UserInfo, []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
}

UserLoaderConfig captures the config to create a new UserLoader

Jump to

Keyboard shortcuts

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