dataloader-sequelize v2.3.3
dataloader-sequelize
Batching, caching and simplification of Sequelize with facebook/dataloader
How it works
dataloader-sequelize is designed to provide per-request caching/batching for sequelize lookups, most likely in a graphql environment
API
createContext(sequelize, object options)
- Should be called after all models and associations are defined
sequelizea sequelize instanceoptions.max=500the maximum number of simultaneous dataloaders to store in memory. The loaders are stored in an LRU cache
Usage
import {createContext, EXPECTED_OPTIONS_KEY} from 'dataloader-sequelize';
/* Per request */
const context = createContext(sequelize); // must not be called before all models and associations are defined
await User.findById(2, {[EXPECTED_OPTIONS_KEY]: context});
await User.findById(2, {[EXPECTED_OPTIONS_KEY]: context}); // Cached or batched, depending on timingPriming
Commonly you might have some sort of custom findAll requests that isn't going through the dataloader. To reuse the results from a call such as this in later findById calls you need to prime the cache:
import {createContext, EXPECTED_OPTIONS_KEY} from 'dataloader-sequelize';
const context = createContext(sequelize);
const results = await User.findAll({where: {/* super complicated */}});
context.prime(results);
await User.findById(2, {[EXPECTED_OPTIONS_KEY]: context}); // Cached, if was in results5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago