oly-sqlize
v0.0.10
Published
Library of Sequelize tools
Downloads
12
Readme
Add curser based pagination to sequelize
Installation
npm install oly-sqlize
Example
// In sequelize models index.js
// es6 modules
import { Paginator } from 'oly-sqlize';
// commonjs
const Paginator = require('oly-sqlize').Paginator;
// Using object destructuring
const { Paginator } = require('oly-sqlize');
// Add pagination options
const paginationOptions = {
methodName: 'paginate',
primaryKeyField: 'id',
};
const addModelPagination = Paginator(paginationOptions);
// Attach to all your models
Object.keys(db).forEach((modelName) => {
if (db[modelName].associate) {
db[modelName].associate(db);
addModelPagination(db[modelName]);
}
});
This package was inspired by https://github.com/Kaltsoon/sequelize-cursor-pagination