Created
March 8, 2021 08:29
-
-
Save timtamimi/c8906df0b84a75e8e356bc5677451f47 to your computer and use it in GitHub Desktop.
Helper for paginating queries in Sequelize
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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