0.1.1 • Published 7 years ago

feathers-batchloader v0.1.1

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

feathers-batchloader

Build Status Code Climate Test Coverage Dependency Status Download Status

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 => {
    // Attach user record
    return usersBatchLoader.load(comment.userId)
      .then(user => comment.userRecord = user);
  }))

License

Copyright (c) 2017 John J. Szwaronek

Licensed under the MIT license.