Get a record
Fetch a single record by its AT URI.
Trigger: xrpc.query:<nsid>. Needs: happyview-db.
local db = require("happyview.db")
function handle(input, ctx) if not input.uri then return { error = "uri parameter is required" } end
local row = db.get(input.uri) if not row then return { error = "not found" } end
return { record = row }endJavaScript
Section titled “JavaScript”import db from "happyview.db";
export default async function handle(input, ctx) { if (!input.uri) { return { error: "uri parameter is required" }; }
const row = await db.get(input.uri); if (!row) { return { error: "not found" }; }
return { record: row };}TypeScript
Section titled “TypeScript”import db from "happyview.db";
interface Input { uri?: string;}
export default async function handle(input: Input) { if (!input.uri) { return { error: "uri parameter is required" }; }
const row = await db.get(input.uri); if (!row) { return { error: "not found" }; }
return { record: row };}How it works
Section titled “How it works”- Check that the
uriquery parameter is present, and return a structured error if not. - Look the record up with
db.get. It returns an envelope,{ uri, did, collection, rkey, cid, indexed_at, record }, or nothing. The record body is the envelope’srecordfield. In JavaScript and TypeScript,db.getreturns a promise, so it is awaited. - Return the envelope wrapped in an object.
The script returns structured errors instead of throwing, so the client gets a body it can handle rather than a 500.
GET /xrpc/xyz.statusphere.getRecord?uri=at://did:plc:abc/xyz.statusphere.status/3k2a
