mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
题解功能
This commit is contained in:
1 parent
ec727d58aa
commit
41261f8c4b
20 files changed
+825
-1277
No files matched your search
@@ -0,0 +1,10 @@
|
||||
const { ValidationError } = require('../error');
|
||||
module.exports = async function paginate(cursor, page, page_size) {
|
||||
if (page <= 0) throw new ValidationError('page');
|
||||
let [count, page_docs] = await Promise.all([
|
||||
cursor.count(),
|
||||
cursor.skip((page - 1) * page_size).limit(page_size).toArray()
|
||||
]);
|
||||
let num_pages = Math.floor((count + page_size - 1) / page_size);
|
||||
return [page_docs, num_pages, count];
|
||||
};
|
||||
Reference in new issue
Block a user