Socket
Socket
Sign inDemoInstall

dataloader-sequelize

Package Overview
Dependencies
26
Maintainers
2
Versions
46
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    dataloader-sequelize

Batching and simplification of Sequelize with facebook/dataloader


Version published
Weekly downloads
12K
decreased by-16.55%
Maintainers
2
Install size
1.49 MB
Created
Weekly downloads
 

Readme

Source

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
  • sequelize a sequelize instance
  • options.max=500 the 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 timing

Priming

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 results

FAQs

Last updated on 21 May 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc