https://github.com/eclass/sequelize-paginate
Sequelize model plugin for add paginate method
https://github.com/eclass/sequelize-paginate
eclass pagination sequelize
Last synced: 11 months ago
JSON representation
Sequelize model plugin for add paginate method
- Host: GitHub
- URL: https://github.com/eclass/sequelize-paginate
- Owner: eclass
- License: mit
- Created: 2018-05-07T20:08:27.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2025-03-07T16:43:15.000Z (12 months ago)
- Last Synced: 2025-03-28T07:03:45.538Z (11 months ago)
- Topics: eclass, pagination, sequelize
- Language: JavaScript
- Size: 1.68 MB
- Stars: 70
- Watchers: 3
- Forks: 19
- Open Issues: 54
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# sequelize-paginate
[](https://www.npmjs.com/package/sequelize-paginate)
[](https://www.npmjs.com/package/sequelize-paginate)
[](https://travis-ci.org/eclass/sequelize-paginate)
[](https://david-dm.org/eclass/sequelize-paginate#info=devDependencies)
> Sequelize model plugin for add paginate method
## Installation
```bash
npm i sequelize-paginate
```
## Use
```js
// 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](https://tldrlegal.com/license/mit-license)