Connect a database
Your app can read and write your own data. This tutorial shows a list of rows from a Supabase table. MySQL works the same way with different connection details.
How it stays safe is described in How it works: the app holds no credentials, and it can only run the reads and writes you approve.
1. Connect the database in Studio
Section titled “1. Connect the database in Studio”Open your project in Studio and go to Database. Choose Supabase and enter:
- a connection name,
- your project URL,
- your anon (publishable) key. Never the service role key: with the anon key, your row level security rules stay in charge.
Studio tests the connection before saving it.
2. Name the connection in the app
Section titled “2. Name the connection in the app”.ynch/connections.json names the connection the app uses. It holds no address and no key:
{ "schemaVersion": "1.0.0", "connections": { "primary": { "cloudConnectionId": "conn_main", "provider": "supabase" } }}3. Describe a row with a model
Section titled “3. Describe a row with a model”Say the table is topics with id, name and description. Create .ynch/models/topic.json:
{ "schemaVersion": "1.0.0", "id": "topic", "identityField": "id", "fields": { "id": { "type": "string", "required": true, "minLength": 36, "maxLength": 36 }, "name": { "type": "string", "required": true, "maxLength": 120 }, "description": { "type": "string", "required": false, "maxLength": 500 } }}4. Declare the read as an operation
Section titled “4. Declare the read as an operation”Create .ynch/operations/list-topics.json:
{ "schemaVersion": "1.0.0", "id": "list-topics", "kind": "list", "connection": "primary", "connector": "supabase", "resource": "topics", "columns": ["id", "name", "description"], "responseModel": "topic", "parameters": {}, "filters": [], "sort": [{ "field": "name", "direction": "asc" }, { "field": "id", "direction": "asc" }], "maxRows": 50, "pagination": { "mode": "offset", "defaultLimit": 25, "maxOffset": 10000 }}This is the whole of what the app may do with that table: read those three columns, sorted by name, up to 50 rows at a time. A list’s sort always ends with the identity field so paging is stable.
5. Show the rows
Section titled “5. Show the rows”In a screen, add a RecordList. Its one child is drawn once per row, and components inside it can show the row’s fields:
{ "id": "topic-list", "type": "RecordList", "props": { "pageSize": 25, "emptyText": "No topics yet" }, "bindings": { "items": { "operationId": "list-topics", "parameters": {}, "pagination": { "offset": 0, "limit": 25 } } }, "children": [ { "id": "topic-item", "type": "Card", "props": {}, "preset": "panel", "children": [ { "id": "topic-name", "type": "Text", "props": {}, "bindings": { "value": { "model": "topic", "field": "name" } } }, { "id": "topic-description", "type": "Text", "props": {}, "bindings": { "value": { "model": "topic", "field": "description" } } } ] } ]}6. Upload, activate, then accept
Section titled “6. Upload, activate, then accept”npx ynch checknpx ynch uploadIn Studio, follow the Releases checklist: approve and sign, make it active, then Accept database changes. Studio shows each operation in plain words (“Read a list of rows from topics”) before you accept.
Open the app on your iPhone. The list loads from your database.
- Models and operations: filters, parameters, and writing data.
- App sign-in: show each user only their own rows.