# Pages that remember what people put in them.

Every space has its own SQLite database, so a published page can be a small app people use together: a tracker, a sign-up sheet, a poll, a labelling desk. There's nothing to set up.

## From document to app

People used to read a published page and comment on it. With a database behind it, they use it: tick a task, sign up, vote, label. What one person adds, everyone who opens the page sees.

Your agent builds the page the way it does now, plus a SQL file that says what the page keeps. Publishing creates the tables.

## In the page

Every HTML page gets `window.cloudtifact.db`. Use `?` placeholders for values. Add `{ objects: true }` to get rows as objects.

```sh
const db = window.cloudtifact.db;

// Everyone who can view the page can read.
const { rows } = await db.query(
  "SELECT choice, COUNT(*) AS votes FROM votes GROUP BY choice", [], { objects: true });

// Members of the space can write, when they open the page in Cloudtifact.
await db.exec("INSERT INTO votes (choice) VALUES (?)", ["tacos"]);
```

index.html

## Tables ship with the page

Put SQL files in a `db/` folder next to the page. `cloudtifact publish` and `cloudtifact push` run each file once, in name order, and remember which ran. To change the tables later, add a new file.

```sh
poll/
  index.html
  db/001_schema.sql   CREATE TABLE IF NOT EXISTS votes (choice TEXT NOT NULL, at TEXT DEFAULT CURRENT_TIMESTAMP);

$ cloudtifact publish poll
db: applied 001_schema.sql
Published "Poll" v1
```

## Try the idea

> An interactive poll: vote or add an option, then pull the results as a TOON table, the way an agent would read a page's data. In this demo the rows stay in your browser.

## Data your agent can read

What a page collects comes back to your agent in one command, as a compact table it can summarise, act on, or build the next version from.

```sh
$ cloudtifact db query "SELECT choice, COUNT(*) AS votes FROM votes GROUP BY choice" --toon
rows[2]{choice,votes}:
  ramen,4
  tacos,7
```

| Command | Does |
| --- | --- |
| cloudtifact db query | Run SQL. Read-only unless you add --write |
| cloudtifact db schema | Tables, columns, row counts, size |
| cloudtifact db export | The whole database as a .sql file |
| cloudtifact db migrate | Run the db/ files without publishing |
| cloudtifact db reset / restore | Wipe it, or roll back to any time in the last 30 days (admins) |

## Who can do what

|  | Read | Write | Reset, restore |
| --- | --- | --- | --- |
| Workspace owners and admins | Yes | Yes | Yes |
| Workspace members | Yes | Yes | No |
| Anyone who can view the page | Yes | No | No |

Pages write only when a member opens them inside Cloudtifact. A page opened by its direct link can read, not write. Each space's database is separate from every other space's, and every write is logged with who made it.

---

Web version: https://cloudtifact.com/databases. Other pages: https://cloudtifact.com/llms.txt
