mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
Hello airbnb
This commit is contained in:
1 parent
f9468536de
commit
8c195661d7
78 files changed
+2032
-1471
No files matched your search
@@ -1,10 +1,11 @@
|
||||
const { ValidationError } = require('../error');
|
||||
module.exports = async function paginate(cursor, page, page_size) {
|
||||
|
||||
module.exports = async function paginate(cursor, page, pageSize) {
|
||||
if (page <= 0) throw new ValidationError('page');
|
||||
let [count, page_docs] = await Promise.all([
|
||||
const [count, pageDocs] = await Promise.all([
|
||||
cursor.count(),
|
||||
cursor.skip((page - 1) * page_size).limit(page_size).toArray()
|
||||
cursor.skip((page - 1) * pageSize).limit(pageSize).toArray(),
|
||||
]);
|
||||
let num_pages = Math.floor((count + page_size - 1) / page_size);
|
||||
return [page_docs, num_pages, count];
|
||||
const numPages = Math.floor((count + pageSize - 1) / pageSize);
|
||||
return [pageDocs, numPages, count];
|
||||
};
|
||||
Reference in new issue
Block a user