This module is designed for the Strongloop Loopback framework. It provides a mixin that makes it possible to limit the number of results returned from an API query.
This works in a similar way to a default scope - the difference being that it acts as a maximum limit constraint ensuring that no more results than the configured maximum will be served by the api, even if requested.
This affects remote remote API calls only and does not apply to internal usage of the API.
npm install --save loopback-ds-resultset-limit-mixin
Then you should register the mixin in your app by adding ../node_modules/loopback-ds-resultset-limit-mixin/lib
to the mixins
property to your server/model-config.json
like the following:
{
"_meta": {
"sources": [
"loopback/common/models",
"loopback/server/models",
"../common/models",
"./models"
],
"mixins": [
"loopback/common/mixins",
"../node_modules/loopback-ds-resultset-limit-mixin/lib",
"../common/mixins"
]
}
}
To use with your Models add the mixins
attribute to the definition object of your model config.
{
"name": "Item",
"properties": {
"name": "String",
"description": "String",
"status": "String"
},
"mixins": {
"ResultsetLimit": {
"limit": 100
}
}
}
Run the tests in test.js
npm test
Run with debugging output on:
DEBUG='loopback:mixin:resultset-limit' npm test