- Examples
Paginated list
List a collection’s records, with cursor pagination and an optional DID filter.
Trigger: xrpc.query:<nsid>. Needs: happyview-db.
local db = require("happyview.db")
function handle(input, ctx) local limit = tonumber(input.limit) or 20 if limit > 100 then limit = 100 end
return db.records("xyz.statusphere.status") :did(input.did) :limit(limit) :cursor(input.cursor) :run()endimport db from "happyview.db";
export default function handle(input, ctx) { const limit = Math.min(Number(input.limit) || 20, 100);
return db.records("xyz.statusphere.status") .did(input.did) .limit(limit) .cursor(input.cursor) .run();}import db from "happyview.db";
interface Input { did?: string; limit?: string | number; cursor?: string;}
export default function handle(input: Input) { const limit = Math.min(Number(input.limit) || 20, 100);
return db.records("xyz.statusphere.status") .did(input.did) .limit(limit) .cursor(input.cursor) .run();}How it works
Section titled “How it works”- Read
limitfrom the query string, defaulting to 20 and capping at 100. Query parameters can arrive as strings, so the script converts it to a number. - Build a
db.recordschain on thexyz.statusphere.statuscollection. A step given no value is skipped, so a request withoutdidorcursorneeds no branching. In JavaScript the argument list ends at the firstundefined, which has the same effect. run()returns{ records, cursor }. Each record is an envelope, andcursoris present when there are more records. In JavaScript and TypeScript,run()returns a promise;handlereturns it and HappyView awaits it.
GET /xrpc/xyz.statusphere.listStatuses?limit=10&did=did:plc:abcGET /xrpc/xyz.statusphere.listStatuses?limit=10&cursor=<cursor from the previous page>© HappyProto

