Skip to content

Instantly share code, notes, and snippets.

View ZachHandley's full-sized avatar

ZachHandley ZachHandley

View GitHub Profile
@ZachHandley
ZachHandley / pagination_func.ts
Last active February 18, 2024 18:55
Appwrite Pagination Function
/**
* listDocumentsPaginated
* Takes a collectionId, lastId, queries, and limit and returns a list of documents
* It's very important to note, if it's the first request, do not pass in a lastId, if it's not the first request, pass in the lastId
* Otherwise known as the current last document's ID in the paginated list
*
* This is best for dynamic lists or LARGE amounts of data
*/
const listDocumentsPaginated = async (collectionId: string, lastId?: string, queries: string[] = [], limit: number = 25, forward: boolean = true): Promise<{ type: "success" | "error", message: string, data: Models.DocumentList<Models.Document>}> => {
try {