Pagination
Use take and skip to implement pagination for large datasets.
Quick Navigation
Basic Pagination
Implement page-based pagination:
import { DataStore } from "@routier/datastore";
import { s } from "@routier/core/schema";
import { MemoryPlugin } from "@routier/memory-plugin";
const productSchema = s.define("products", {
_id: s.string().key().identity(),
name: s.string(),
price: s.number(),
category: s.string(),
inStock: s.boolean(),
tags: s.string("computer", "accessory").array(),
createdDate: s.date().default(() => new Date())
}).compile();
class AppDataStore extends DataStore {
products = this.collection(productSchema).create();
constructor() {
super(new MemoryPlugin("app"));
}
}
const dataStore = new AppDataStore();
// Pagination - get second page (skip first 10, take next 10)
const pageSize = 10;
const pageNumber = 2; // 0-based
const secondPage = await dataStore.products
.skip(pageSize * pageNumber)
.take(pageSize)
.toArrayAsync();Simple Take and Skip
>