sequelize-paginate
TypeScript icon, indicating that this package has built-in type declarations

1.1.6 • Public • Published

sequelize-paginate

npm version npm downloads Build Status devDependency Status

Sequelize model plugin for add paginate method

Installation

npm i sequelize-paginate

Use

// model.js
const sequelizePaginate = require('sequelize-paginate')
 
module.exports = (sequelize, DataTypes) => {
  const MyModel = sequelize.define(
    'MyModel',
    {
      name: { type: DataTypes.STRING(255) }
    }
  )
  sequelizePaginate.paginate(MyModel)
  return MyModel
}
 
// controller.js
const { Op } = db.sequelize
// Default page = 1 and paginate = 25
const { docs, pages, total } = await db.MyModel.paginate()
// Or with extra options
const options = {
  attributes: ['id', 'name'],
  page: 1, // Default 1
  paginate: 25, // Default 25
  order: [['name', 'DESC']],
  where: { name: { [Op.like]: `%elliot%` } }
}
const { docs, pages, total } = await db.MyModel.paginate(options)

NOTE: If options include limit or offset are ignored.

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i sequelize-paginate

Weekly Downloads

2,125

Version

1.1.6

License

MIT

Unpacked Size

12.2 kB

Total Files

9

Last publish

Collaborators

  • lgatica