Connect your database
Every custom app can use the [data tables](https://openthink.app/n/e4a246ac3902) in its space as its database. There's nothing to set up — no server, no API key, no connection string. The app reads and writes rows with SQL, and the same rows show up in the table, in embedded charts and in [SQL blocks](https://openthink.app/n/08d0ba345c4a).
Where the data lives
- An app can use every data table in the **same space** as the app. Tables in other spaces are out of reach.
- You design the schema in the table itself: add columns and pick their types (text, number, select, date, checkbox…). SQL can't create or change columns.
- Each row has a hidden `_id` column — use it to update or delete the right row.
Read rows
```js
const { rows } = await think.executeSql(
'SELECT _id, "Name", "Amount" FROM "Expenses" WHERE "Amount" > ?',
[100000]
);
```
The dialect is SQLite. Refer to tables and columns by their names in double quotes, exactly as they appear in the tree.
Write rows
```js
await think.executeSql(
'INSERT INTO "Expenses" ("Name", "Amount", "Date") VALUES (?, ?, ?)',
["Lunch", 85000, "2026-11-26"]
);
await think.executeSql('UPDATE "Checklist" SET "Done" = 1 WHERE _id = ?', [id]);
```
`INSERT`, `UPDATE` and `DELETE` really change the table, and every place showing it updates.
Values by column type
| Column type | In SQL |
|---|---|
| Number | A plain number (money too) |
| Date | Text `'yyyy-mm-dd'` |
| Checkbox | `0` or `1` |
| Select | The option name — a new name adds the option |
| Multi-select | Option names joined by `", "` |
Good practice
- **Always pass user input as parameters** (`?` with an array, or `:name` with an object). Never build SQL strings from what people type.
- **Load tables together.** Use `Promise.all` instead of waiting for each query in turn — the page opens faster.
- **Pick the right store.** Long-term or shared data → tables. A selected tab or year → [URL parameters](https://openthink.app/n/880ac6e69d53) with `think.params`. What's on one person's screen right now → `think.state` (see [Live collaboration](https://openthink.app/n/5b39c176b328)).
- `localStorage` is wiped when the page reloads — don't keep anything there.
Next
- [Live collaboration](https://openthink.app/n/5b39c176b328) — redraw when the data changes elsewhere
- [Authentication, authorization & accounting](https://openthink.app/n/b78dd1e6ad82) — who may read and write which rows
- Full reference: [HTML page API](https://openthink.app/n/880ac6e69d53)