Skip to content

Instantly share code, notes, and snippets.

@bhubr
Created January 15, 2019 13:16
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 bhubr/eed508f9c95604e33ad89a29507a6d8e to your computer and use it in GitHub Desktop.
Save bhubr/eed508f9c95604e33ad89a29507a6d8e to your computer and use it in GitHub Desktop.
Pagination Express SQL
const { page } = req.query;
let limit = '';
if (page) {
const skip = Number(page) * 10 // Si tu as 10 items par page
limit = `LIMIT ${skip},10`; // skip définit le nombre d'items à "passer" pour arriver à ceux qu'on veut obtenir
}
db.query(`SELECT * FROM user ORDER BY ID DESC ${limit}`), (err, res) => {
// ...
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment