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 BatchFetchers
to actually retrieve the data). For other operations including mutations
or more advanced query operations, see the BatchExecutor type and
the Executor trait.
Structs§
- BatchExecutor 
- Batches calls to an Executor, such as for bulk inserting, updating, or deleting records in a datastore.BatchExecutors are asynchronous and designed to be passed and shared between threads or tasks. Cloning aBatchExecutoris shallow and will use the same underlyingExecutor.
- BatchExecutor Builder 
- Used to configure a new BatchExecutor. ABatchExecutorBuilderis returned fromBatchExecutor::build.
- BatchFetcher 
- Batches and caches loads from some datastore. A BatchFetchercan be used with any type that implementsFetcher.BatchFetchers are asynchronous and designed to be passed and shared between threads or tasks. Cloning aBatchFetcheris shallow and will use the sameFetcher.
- BatchFetcher Builder 
- Used to configure a new BatchFetcher. ABatchFetcherBuilderis returned fromBatchFetcher::build.
- Cache
- Holds the results of loading a batch of data from a Fetcher. Implementors ofFetchershould callinsertfor each value that was loaded in a batch request.
Enums§
- ExecuteError 
- Error indicating that execution of one or more values from a
BatchExecutorfailed.
- LoadError 
- Error indicating that loading one or more values from a BatchFetcherfailed.
Traits§
- Executor
- A trait for using a batch of values to execute some operation, such
as a bulk insertion in a datastore. An Executorwill be given an array of values and should handle each value, then return a result for each. ImplementingExecutorwill allow operations to be batched by using aBatchExecutor. See theBatchExecutordocs for details about batching and error semantics.
- Fetcher
- A trait for fetching values from some datastore in bulk. A Fetcherwill be given an array of keys and should insert fetched values into a given cache. ImplementingFetcherwill allow queries to be batched using aBatchFetcher. See theBatchFetcherdocs for details about batching, caching, and error semantics.