Skip to content

b3rew/loopback-row-count-mixin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

A loopback mixin to get total count of a model

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published