Expand description
Batch and cache database queries, mutations, or other potentially expensive operations. The main motivation for this library is to solve the “N + 1” query problem seen in GraphQL and elsewhere. This library takes heavy influence from the GraphQL Foundation’s DataLoader.
For batched data queries, see the BatchFetcher
type (used to queue and
load data in batches) and the Fetcher
trait (used by BatchFetcher
s
to actually retrieve the data). For other operations including mutations
or more advanced query operations, see the BatchExecutor
type and
the Executor
trait.
Structs§
- Batch
Executor - Batches calls to an
Executor
, such as for bulk inserting, updating, or deleting records in a datastore.BatchExecutor
s are asynchronous and designed to be passed and shared between threads or tasks. Cloning aBatchExecutor
is shallow and will use the same underlyingExecutor
. - Batch
Executor Builder - Used to configure a new
BatchExecutor
. ABatchExecutorBuilder
is returned fromBatchExecutor::build
. - Batch
Fetcher - Batches and caches loads from some datastore. A
BatchFetcher
can be used with any type that implementsFetcher
.BatchFetcher
s are asynchronous and designed to be passed and shared between threads or tasks. Cloning aBatchFetcher
is shallow and will use the sameFetcher
. - Batch
Fetcher Builder - Used to configure a new
BatchFetcher
. ABatchFetcherBuilder
is returned fromBatchFetcher::build
. - Cache
- Holds the results of loading a batch of data from a
Fetcher
. Implementors ofFetcher
should callinsert
for each value that was loaded in a batch request.
Enums§
- Execute
Error - Error indicating that execution of one or more values from a
BatchExecutor
failed. - Load
Error - Error indicating that loading one or more values from a
BatchFetcher
failed.
Traits§
- Executor
- A trait for using a batch of values to execute some operation, such
as a bulk insertion in a datastore. An
Executor
will be given an array of values and should handle each value, then return a result for each. ImplementingExecutor
will allow operations to be batched by using aBatchExecutor
. See theBatchExecutor
docs for details about batching and error semantics. - Fetcher
- A trait for fetching values from some datastore in bulk. A
Fetcher
will be given an array of keys and should insert fetched values into a given cache. ImplementingFetcher
will allow queries to be batched using aBatchFetcher
. See theBatchFetcher
docs for details about batching, caching, and error semantics.