docs(website): fill the six Reference stubs with worked examples + output

Expand columns, relationships, indexes, constraints, inserting-and-editing-
data, and querying-and-inspecting from syntax-only stubs into full pages,
each with worked examples on the library schema and real captured app output
(structure boxes, relationship diagrams, data tables, show-lists, query
plans, cascade summaries). All output captured verbatim from the app — never
hand-drawn. Both simple- and advanced-mode forms shown where both apply;
advanced syntax verified against tests/source.

STYLE.md: record the output-block convention (plain unlabelled fence,
captured from a throwaway harness, not hand-drawn).

Verified: pnpm build clean (24 pages); no forbidden terms; internal links
and heading anchors resolve.
This commit is contained in:
claude@clouddev1
2026-06-10 11:50:18 +00:00
parent 619c200ea1
commit 10655e46de
7 changed files with 674 additions and 96 deletions
@@ -1,26 +1,117 @@
---
title: Inserting & editing data
description: Add, change, and remove rows.
description: Add, change, and remove rows — with required filters and automatic confirmation of what changed.
sidebar:
order: 7
---
:::note[In progress]
The syntax below is complete and accurate; worked examples on the library
schema are being added.
:::
Once your tables exist, you fill them with rows and keep them up to date. The
examples use the [example library](/getting-started/example-library/). After
every write, the playground shows you the rows that changed, so you can confirm
the effect at a glance.
## Inserting rows
List the columns you are providing, then the matching values:
```rdbms
insert into members (name, joined) values ('Katherine Johnson', '2024-06-01')
```
```
1 row(s) inserted
┌───────────┬───────────────────┬────────────┐
│ member_id │ name │ joined │
├───────────┼───────────────────┼────────────┤
│ 3 │ Katherine Johnson │ 2024-06-01 │
└───────────┴───────────────────┴────────────┘
```
Notice that `member_id` was filled in automatically — it is a `serial` column,
so you leave it out of the `insert` and the database assigns the next value.
The same applies to `shortid` columns and to any column with a
[default](/reference/constraints/) (see [Types](/reference/types/)).
## Updating rows
`update` changes columns on the rows that match a filter:
```rdbms
update books set published = 1970 where book_id = 2
```
```
1 row(s) updated
┌─────────┬───────────────────────────┬───────────┬───────────┬────────────────┐
│ book_id │ title │ author_id │ published │ isbn │
├─────────┼───────────────────────────┼───────────┼───────────┼────────────────┤
│ 2 │ The Left Hand of Darkness │ 1 │ 1970 │ 978-0441478125 │
└─────────┴───────────────────────────┴───────────┴───────────┴────────────────┘
```
## Deleting rows
```rdbms
delete from authors where author_id = 3
```
When the deleted row has children linked by an `on delete cascade`
[relationship](/reference/relationships/), those children are removed too, and
the result reports each affected relationship:
```
1 row(s) deleted
related: 1 row(s) deleted in `books` for relationship `books_author` (on delete cascade)
```
## The required filter
`update` and `delete` **must** have a `where` clause. This is a safety rail: it
is far too easy to wipe or rewrite a whole table by forgetting one. When you
really do mean every row, say so explicitly with `--all-rows`:
```rdbms
update books set published = 2000 --all-rows
delete from loans --all-rows
```
```rdbms-syntax
update <Table> set <col>=<value>[, ...] (where <expr> | --all-rows)
delete from <Table> (where <expr> | --all-rows)
```
## Richer filters
A `where` clause is more than simple equality. It accepts `and` / `or` /
`not`, the comparison operators, and `like`, `is null`, `in`, and `between`:
```rdbms
delete from loans where returned_on is null and loaned_on < '2024-01-01'
```
The same expression grammar drives `show data` — see
[Querying & inspecting](/reference/querying-and-inspecting/).
## In advanced mode
The simple-mode commands above already use SQL-like syntax; advanced mode is
full SQL, including multi-row inserts and `returning`:
```sql
insert into members (name, joined) values
('Katherine Johnson', '2024-06-01'),
('Dorothy Vaughan', '2024-06-02')
update books set published = 1970 where book_id = 2
delete from authors where author_id = 3
```
## Syntax
```rdbms-syntax
insert into <Table> [(<col>[, ...])] [values] (<value>[, ...])
update <Table> set <col>=<value>[, ...] (where <col>=<value> | --all-rows)
delete from <Table> (where <col>=<value> | --all-rows)
update <Table> set <col>=<value>[, ...] (where <expr> | --all-rows)
delete from <Table> (where <expr> | --all-rows)
```
`update` and `delete` require a `where` clause; to act on every row you must
opt in explicitly with `--all-rows`. Auto-generated columns (`serial`,
`shortid`) fill themselves in, so you can leave them out of an `insert`. After
a write, the affected rows are shown automatically.
`where` accepts more than simple equality — `and` / `or` / `not`,
comparisons, `like`, `is null`, `in`, and `between`. See
[Querying & inspecting](/reference/querying-and-inspecting/).
See also [Querying & inspecting](/reference/querying-and-inspecting/) and
[Constraints](/reference/constraints/).