router.get("/members", (req, res) => {
let page = req.query.page;
let pageSize = req.query.pageSize;
if (typeof page === "undefined") {
page = 0;
} else {
page -= 1;
}
if (typeof pageSize === "undefined") {
pageSize = 5;
}
var skip = page * pageSize;
db.sequelize.query(
"SELECT id, mbr_id, mbr_name, mbr_type " +
"FROM tbl_members " +
"LIMIT " + pageSize + " " +
"OFFSET " + skip
)
.then(members => {
res.json(members[0])
})
.catch(err => {
res.send("error: " + err)
})
})
I would like to add another mysql query. How do I modify my code so that I can add another mysql query and I add the result to the res variable. The query I like to add is getting the total number of records of the query above without the limit and offset. Going to use this for pagination.
Additionally, do I have to use async/await server side? My client side already has async/await before calling my code above. I've read this thread before I posted this. It has sample codes and some explanation. It talks about parallel with promise -- I do not require parallel query execution, just that I execute more than one query in a single router.get().
I also prefer using MySQL statement as I was used to SQL statements and not so much on ORM especially on defining relationship and using aggregates -- still confusing for now.