List or Fetch
This query handles both single-record lookups (when a uri param is provided) and paginated listing.
Lexicon type: query
local db = require("happyview.db")
function handle(input, ctx) if input.uri then local row = db.get(input.uri) if not row then return { error = "record not found" } end return { record = row } end
return db.records(ctx.collection) :did(input.did) :limit(tonumber(input.limit) or 20) :cursor(input.cursor) :run()endHow it works
Section titled “How it works”- If a
uriquery parameter is provided, fetch that single record withdb.getand return it. If it doesn’t exist, return a structured error (usingerror()would trigger a 500 response). - Otherwise, list records from the target collection with a
db.recordschain, with optional filtering bydidand cursor-based pagination. Thecursoris an opaque string from a previous response — pass it through directly. Alimitthe lexicon declares as anintegerarrives as a number already;tonumber()covers a lexicon that leaves it untyped, where it arrives as a string.
GET /xrpc/xyz.statusphere.listRecords?limit=10GET /xrpc/xyz.statusphere.listRecords?did=did:plc:abcGET /xrpc/xyz.statusphere.listRecords?uri=at://did:plc:abc/xyz.statusphere.record/abc123Use case
Section titled “Use case”Useful when one endpoint needs to handle both listing and single-record fetches.

