0.3.6 • Published 6 years ago

@feathers-plus/batch-loader v0.3.6

Weekly downloads
16,606
License
MIT
Repository
github
Last release
6 years ago

feathers-plus/batch-loader

Build Status Code Climate Test Coverage Dependency Status Download Status

Reduce requests to backend services by batching calls and caching records.

Installation

npm install @feathers-plus/batch-loader --save

Documentation

Please refer to the batch-loader documentation for more details.

Complete Example

Here's an example of a Feathers server that uses feathers-plus/batch-loader.

const BatchLoader = require('@feathers-plus/batch-loader');
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 => Promise.all(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.

0.3.6

6 years ago

0.3.5

6 years ago

0.3.4

7 years ago

0.3.3

7 years ago

0.3.2

7 years ago

0.3.1

7 years ago

0.3.0

8 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago