Resource

A resource is a collection of data that is stored in the database. For models that don’t require a frontend interface, you can use the resource generator to create the collection and its schema. For existing models, the fields option can be omitted and the generator will use the existing fields.

Syntax

$ vela generate resource <model> [fields...]
$ vela generate resource categories name:text

This will create the database collection, the migration that creates it elsewhere, and a Zod schema definition for the resource. The files created are:

migrations/<timestamp>_created_categories.js
src/lib/schemas/category.ts

The categories collection is created in the local database and the TypeScript definitions are synced. Commit the migration: it is what creates the collection on a deploy and on a teammate’s machine.

A resource has no pages. Unlike scaffold, no routes, forms or components are generated; run vela generate scaffold categories with the same fields to add list, detail and form pages later.

Options

  • --rules <auth|owner|superuser> - Who may read and write the collection through the API. auth: any signed-in user. owner: the record’s owner. superuser: server only, with no API access, so your code has to use locals.admin. Left out, the rules follow from the fields. See Rules.
$ vela generate resource audit_logs action:text! actor:user --rules superuser

--help prints the whole field syntax, including the :unique modifier. To design a model from a description, use generate scaffold --ai or generate schema --ai. To place routes at a custom path, use generate scaffold --route.