feathers-batchloader
Reducs calls
Installation
npm install feathers-batchloader --save
Documentation
Please refer to the feathers-batchloader documentation for more details.
Complete Example
Here's an example of a Feathers server that uses feathers-batchloader
.
const BatchLoader = require('feathers-batchloader');
const { getResultsByKey, getUniqueKeys } = BatchLoader;
const usersBatchLoader = new BatchLoader(
keys => app.service('users').find({ query: { id: { $in: getUniqueKeys(keys) } } })
.then(result => getResultsByKey(keys, result, user => user.id, '!'))
);
app.service('comments').find()
.then(comments => comments.map(comment => {
return usersBatchLoader.load(comment.userId)
.then(user => comment.userRecord = user);
}))
License
Copyright (c) 2017 John J. Szwaronek
Licensed under the MIT license.