-
Notifications
You must be signed in to change notification settings - Fork 158
feat: add server-side pagination to API endpoints #1464
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 21 commits
7d5c31a
8541fb5
2bb4bfa
74895fd
bf9863c
2188282
a0a8b5d
af7d290
16fac86
c76e4a1
85e3666
c5096ba
d079512
7ab5852
3a3891f
56922f9
7716b4d
965efa0
4c95924
e39c460
ab824d6
925c6bc
e7fc82f
367226f
8b545ab
a68cb70
a611fb9
c5ecc98
2c222a9
a09117d
eaaf5de
876b185
259b51a
6beb5f1
212acdf
846d33e
06b6af7
8dc82dc
e737d6e
6c7d262
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,8 +15,40 @@ | |
| */ | ||
|
|
||
| import { existsSync, mkdirSync } from 'fs'; | ||
| import Datastore from '@seald-io/nedb'; | ||
| import { PaginatedResult } from '../types'; | ||
|
|
||
| export const getSessionStore = (): undefined => undefined; | ||
| export const initializeFolders = () => { | ||
| if (!existsSync('./.data/db')) mkdirSync('./.data/db', { recursive: true }); | ||
| }; | ||
|
|
||
| export const paginatedFind = <T>( | ||
| db: Datastore, | ||
| filter: Record<string, unknown>, | ||
| sort: Record<string, 1 | -1>, | ||
| skip: number, | ||
| limit: number, | ||
| ): Promise<PaginatedResult<T>> => { | ||
| const countPromise = new Promise<number>((resolve, reject) => { | ||
| db.count(filter as any, (err: Error | null, count: number) => { | ||
| /* istanbul ignore if */ | ||
| if (err) reject(err); | ||
| else resolve(count); | ||
| }); | ||
| }); | ||
|
|
||
| const dataPromise = new Promise<T[]>((resolve, reject) => { | ||
| db.find(filter as any) | ||
| .sort(sort) | ||
| .skip(skip) | ||
| .limit(limit) | ||
| .exec((err: Error | null, docs: any[]) => { | ||
| /* istanbul ignore if */ | ||
| if (err) reject(err); | ||
| else resolve(docs); | ||
| }); | ||
| }); | ||
|
|
||
| return Promise.all([dataPromise, countPromise]).then(([data, total]) => ({ data, total })); | ||
|
||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can use
PaginatedResulttype hereThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the
/pushendpoint now returns pushes instead of data.