Use this when local data files need related records but you still want plain ids in JSON. It demonstrates to-one relation metadata, explicit REST expand, and nested select.
- db/users.schema.jsonc: target collection.
- db/posts.schema.jsonc:
authorIddeclares a relation tousers.id. - db.config.js: default mirror setup using
defineConfig.
From the repository root, use the repo-internal CLI path:
pnpm run db -- sync --cwd ./examples/relations
pnpm run db -- serve --cwd ./examples/relationsOpen the local data explorer:
http://127.0.0.1:7331/__dbThe local data explorer lists posts and users. The posts schema shows an author relation derived from authorId.
Leave serve running and run this from another terminal:
curl 'http://127.0.0.1:7331/db/posts.json?expand=author&select=id,title,author.name'Relation expansion is intentionally explicit and depth 1 in this version.
Generated .db/ output is ignored by git and can be removed whenever you want a fresh mirror.