Models and operations
An app works with your database through two kinds of file. A model describes a row. An operation is one specific read or write. Start with Connect a database if you have not set one up.
Models
Section titled “Models”{ "schemaVersion": "1.0.0", "id": "workout", "identityField": "id", "fields": { "id": { "type": "integer", "required": true, "generated": true }, "name": { "type": "string", "required": true, "minLength": 1, "maxLength": 80 }, "duration": { "type": "integer", "required": true, "minimum": 1, "maximum": 600 }, "completed": { "type": "boolean", "required": true }, "day": { "type": "date", "required": false } }}- Field types:
string,number,integer,boolean,date(YYYY-MM-DD). identityFieldnames the field that identifies a row. Only it may begenerated(set by the database).- Strings can have
minLength,maxLengthand a fixedenumlist; numbers can haveminimumandmaximum. - A hyphen in a name is an underscore in the database:
topic-idis the columntopic_id.
Operations
Section titled “Operations”Each operation names its table (resource), the columns it touches, and the model its rows match.
| Kind | Does | Notes |
|---|---|---|
list |
Reads many rows | Filters, sort and paging. Up to 100 rows a page. |
get |
Reads one row | Filtered by the identity field. |
insert |
Adds one row | values maps fields to parameters. |
update |
Changes one row | Filtered by the identity field. |
delete |
Removes one row | Filtered by the identity field. |
A list with a filter:
{ "schemaVersion": "1.0.0", "id": "list-cards", "kind": "list", "connection": "primary", "connector": "supabase", "resource": "cards", "columns": ["id", "topic-id", "question"], "responseModel": "card", "parameters": { "topic-id": { "type": "string", "required": true, "minLength": 36, "maxLength": 36 } }, "filters": [{ "field": "topic-id", "operator": "eq", "parameter": "topic-id" }], "sort": [{ "field": "id", "direction": "asc" }], "maxRows": 50, "pagination": { "mode": "offset", "defaultLimit": 20, "maxOffset": 10000 }}- Parameters are the only values that come from the app at run time. They are typed like model fields.
- Filters compare a field with a parameter using
eq,lt,lte,gtorgte. Up to 10, all of which must match. - Sort takes up to three fields and, for a list, ends with the identity field.
An insert:
{ "schemaVersion": "1.0.0", "id": "create-workout", "kind": "insert", "connection": "primary", "connector": "supabase", "resource": "workouts", "columns": ["id", "name", "duration", "completed"], "responseModel": "workout", "parameters": { "name": { "type": "string", "required": true, "minLength": 1, "maxLength": 80 }, "duration": { "type": "integer", "required": true, "minimum": 1, "maximum": 600 }, "completed": { "type": "boolean", "required": true } }, "values": { "name": "name", "duration": "duration", "completed": "completed" }, "maxRows": 1}There are no joins, no SQL and no “or” conditions. If you need a combined view, create a view in your database and point an operation at it.
Using operations on a screen
Section titled “Using operations on a screen”- A
RecordListruns alistoperation and draws its child for each row. - A
Formsaves with aninsertorupdateoperation; its inputs bind to the model’s fields. - A
Buttoncan run an operation directly with"action": { "type": "operation", ... }.
Approval
Section titled “Approval”Declaring an operation gives the app nothing by itself. After you make a version active, Studio lists each operation it asks for in plain words, and nothing runs until you accept. If you change an operation’s table, columns, filters or values, it needs accepting again. You can revoke one at any time on the Database tab.
Counting requests
Section titled “Counting requests”Each operation the app runs counts as one data request against your project’s monthly allowance, shown on the app’s detail screen and in Studio.