Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/eclass/sequelize-paginate
Sequelize model plugin for add paginate method
https://github.com/eclass/sequelize-paginate
eclass pagination sequelize
Last synced: 2 days 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 (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-11-19T12:03:36.000Z (about 1 month ago)
- Last Synced: 2024-12-13T12:12:44.803Z (9 days ago)
- Topics: eclass, pagination, sequelize
- Language: JavaScript
- Size: 1.69 MB
- Stars: 70
- Watchers: 4
- Forks: 19
- Open Issues: 55
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# sequelize-paginate
[![npm version](https://img.shields.io/npm/v/sequelize-paginate.svg)](https://www.npmjs.com/package/sequelize-paginate)
[![npm downloads](https://img.shields.io/npm/dm/sequelize-paginate.svg)](https://www.npmjs.com/package/sequelize-paginate)
[![Build Status](https://travis-ci.org/eclass/sequelize-paginate.svg?branch=master)](https://travis-ci.org/eclass/sequelize-paginate)
[![devDependency Status](https://img.shields.io/david/dev/eclass/sequelize-paginate.svg)](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)