Created
January 15, 2019 13:16
-
-
Save bhubr/eed508f9c95604e33ad89a29507a6d8e to your computer and use it in GitHub Desktop.
Pagination Express SQL
This file contains 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
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