Skip to content

Instantly share code, notes, and snippets.

@timtamimi
Created March 8, 2021 08:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timtamimi/c8906df0b84a75e8e356bc5677451f47 to your computer and use it in GitHub Desktop.
Save timtamimi/c8906df0b84a75e8e356bc5677451f47 to your computer and use it in GitHub Desktop.
Helper for paginating queries in Sequelize
// Helper function 👇
const paginate = (query, { page, pageSize }) => {
const offset = page * pageSize;
const limit = pageSize;
return {
...query,
offset,
limit,
};
};
// Example usage 👇
model.findAll(
paginate(
{
where: {}
},
{ page, pageSize }
),
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment