loopback-row-count-mixin

A mixin to get total count of a model for a loopback Model.

Usage no npm install needed!

<script type="module">
  import loopbackRowCountMixin from 'https://cdn.skypack.dev/loopback-row-count-mixin';
</script>

README

loopback-row-count-mixin

A mixin to get total count of a model for pagination in a loopback Model.

INSTALL

npm install --save loopback-row-count-mixin
you can enable mixin by editing server.js:

In your server/server.js file add the following line before the boot(app, __dirname); line.

...
var app = module.exports = loopback();
...
// Add Counts Mixin to loopback
require('loopback-row-count-mixin')(app);

boot(app, __dirname, function(err) {
  'use strict';
  if (err) throw err;

  // start the server if `$ node server.js`
  if (require.main === module)
    app.start();
});

CONFIG

To use with your Models add the mixins attribute to the definition object of your model config.

{
  "name": "player",
  "properties": {
    "name": "string",
    "type": "string",
  },
  "mixins": {
    "RowCount": true
  }
}

USAGE

EXAMPLE

http://0.0.0.0:3000/api/players

will return list of players with field to help for you pagination

{
    "count": 2,
    "rows": [
      {
        "id": 1,
        "title": "First player",
        "type": ""
      },
      {
        "id": 2,
        "title": "Second player",
        "type": ""
      }
    ]
}

LICENSE

MIT