docs(website): document m:n, --demo, schema sidebar, responsive input

Document the features the main merge shipped: `create m:n relationship`
(relationships ref + build-the-library note), the `--demo` teaching
flag (command-line-options), the Ctrl-O schema sidebar (output-pane,
now .mdx to embed the new cast), and horizontal/two-row input
(assistive-editor).
This commit is contained in:
claude@clouddev1
2026-06-11 12:26:31 +00:00
parent 823b413ca3
commit 6778c338d4
6 changed files with 97 additions and 22 deletions
@@ -102,6 +102,15 @@ add 1:n relationship as loans_book from books.book_id to loans.book_id on delete
add 1:n relationship as loans_member from members.member_id to loans.member_id on delete cascade add 1:n relationship as loans_member from members.member_id to loans.member_id on delete cascade
``` ```
:::note
We build the bridge by hand here because `loans` carries its own columns
(`loaned_on`, `returned_on`) — it records *when* each borrowing happened, not
just *that* it did. For a pure link with no extra columns, the
`create m:n relationship` command builds the junction table and both
relationships in one step — see
[Many-to-many relationships](/reference/relationships/#many-to-many-relationships).
:::
You can confirm all three relationships at once: You can confirm all three relationships at once:
```rdbms ```rdbms
@@ -123,6 +123,47 @@ list the columns on each side, matched in order:
add 1:n relationship from <Parent>.(<a>, <b>) to <Child>.(<x>, <y>) add 1:n relationship from <Parent>.(<a>, <b>) to <Child>.(<x>, <y>)
``` ```
## Many-to-many relationships
When two tables relate **many-to-many** — a student takes many courses, and a
course has many students — you model it with a **junction table** (also called
a bridge table) that holds a foreign key to each side. `create m:n
relationship` builds that junction for you in one step:
```rdbms
create m:n relationship from Students to Courses
```
Assuming each parent has a primary key `id`, this creates a table named
`Students_Courses` with:
- one foreign-key column per primary-key column of each parent —
`Students_id` and `Courses_id`, typed to match the keys they reference;
- a **compound primary key** over those columns, so the same pair can never be
linked twice;
- two `1:n` relationships (junction → `Students`, junction → `Courses`), each
with `on delete cascade` and `on update cascade` — delete a student or a
course and its link rows go with it.
The junction is an ordinary table afterwards: `rename table`, `drop table`,
`insert`, or `add column` all work on it. To choose the name yourself, add
`as <name>`:
```rdbms
create m:n relationship from Students to Courses as Enrollments
```
A few rules keep it predictable:
- Both parents need a primary key — that is what the junction references.
- The two tables must be different; there is no self-referential shorthand.
To link a table to itself, build the junction by hand.
- The generated foreign keys always cascade. If you need different
[referential actions](#referential-actions), or extra columns on the link
from the start (a loan date, say), build the junction by hand instead — a
`create table` plus two `add 1:n relationship` commands, as the
[library guide](/guides/build-the-library/) does for its `loans` table.
## Removing a relationship ## Removing a relationship
```rdbms ```rdbms
@@ -145,6 +186,7 @@ add 1:n relationship [as <Name>]
from <Parent>.<col> to <Child>.<col> from <Parent>.<col> to <Child>.<col>
[on delete <action>] [on update <action>] [on delete <action>] [on update <action>]
[--create-fk] [--create-fk]
create m:n relationship from <T1> to <T2> [as <Name>]
drop relationship <Name> drop relationship <Name>
``` ```
@@ -27,6 +27,7 @@ rdbms-playground path/to/project
| `--mode <simple\|advanced>` | Start in this input mode, overriding the project's stored mode (precedence: `--mode` > stored > simple). | | `--mode <simple\|advanced>` | Start in this input mode, overriding the project's stored mode (precedence: `--mode` > stored > simple). |
| `--theme <light\|dark>` | Force a theme instead of auto-detecting from the terminal. | | `--theme <light\|dark>` | Force a theme instead of auto-detecting from the terminal. |
| `--no-undo` | Disable the undo machinery for this run — no snapshot is taken before each change (see [Undo, redo & history](/using-the-playground/undo-and-history/)). | | `--no-undo` | Disable the undo machinery for this run — no snapshot is taken before each change (see [Undo, redo & history](/using-the-playground/undo-and-history/)). |
| `--demo` | Turn on demonstration mode — a teaching aid that briefly shows an on-screen badge for keys that otherwise leave no visible mark (Tab, Enter, the arrows, and the like). Useful for screencasts and for demonstrating the playground to a class. Off by default. |
| `--log-file <PATH>` | Write diagnostic logging to `PATH`. | | `--log-file <PATH>` | Write diagnostic logging to `PATH`. |
| `-h`, `--help` | Print the usage banner and exit. | | `-h`, `--help` | Print the usage banner and exit. |
@@ -52,6 +52,10 @@ by character, <kbd>Home</kbd>/<kbd>End</kbd> to the ends, and
<kbd>Delete</kbd>/<kbd>Backspace</kbd> to remove characters. Your <kbd>Delete</kbd>/<kbd>Backspace</kbd> to remove characters. Your
project-scoped command history is available with <kbd>↑</kbd>/<kbd>↓</kbd>. project-scoped command history is available with <kbd>↑</kbd>/<kbd>↓</kbd>.
A long command does not get cut off: the line scrolls sideways to keep the
cursor in view, and on a tall terminal the input field uses two rows so you
can see more of it at once.
:::note[Planned] :::note[Planned]
Multi-line entry and extra readline-style shortcuts (Ctrl-A/E/W/K/U) are Multi-line entry and extra readline-style shortcuts (Ctrl-A/E/W/K/U) are
planned and not yet available. planned and not yet available.
@@ -1,22 +0,0 @@
---
title: The output pane
description: Where results appear, and how to scroll back through them.
sidebar:
order: 3
---
Results appear in the output pane: the structure of a table after you change
it, the rows from `show data` and after writes (as aligned, box-drawn
tables), query plans, and command outcomes marked with a ✓ or ✗.
## Scrolling
Use <kbd>PageUp</kbd> and <kbd>PageDown</kbd> to scroll back through earlier
output. New output snaps the view back to the most recent entry, so you never
lose your place when you run something.
:::note[Planned]
A fuller session journal — a scrollable, richly rendered log of the whole
session that you can save as Markdown — and multiple result tabs are planned
and not yet available.
:::
@@ -0,0 +1,41 @@
---
title: The output pane
description: Where results appear, the schema sidebar, and how to scroll back through them.
sidebar:
order: 3
---
import Demo from '../../../components/Demo.astro';
Results appear in the output pane: the structure of a table after you change
it, the rows from `show data` and after writes (as aligned, box-drawn
tables), query plans, and command outcomes marked with a ✓ or ✗.
## Scrolling
Use <kbd>PageUp</kbd> and <kbd>PageDown</kbd> to scroll back through earlier
output. New output snaps the view back to the most recent entry, so you never
lose your place when you run something.
## The schema sidebar
On a wide terminal a sidebar runs down the left-hand side, listing your
**tables** and **relationships** so the shape of your database is always in
view. It shows and hides itself automatically with the terminal width — on a
narrow window it stays out of the way and the output pane gets the full width.
Press <kbd>Ctrl-O</kbd> to bring the sidebar up at any size and step through
it: the first press focuses the **Tables** panel, the next focuses
**Relationships**, and once more returns you to the input field
(<kbd>Esc</kbd> leaves it directly). While a panel is focused it widens to
show more detail and is marked with a coloured border;
<kbd>↑</kbd>/<kbd>↓</kbd> scroll it a line at a time and
<kbd>PageUp</kbd>/<kbd>PageDown</kbd> a page at a time.
<Demo src="/casts/schema-sidebar.cast" title="Ctrl-O brings up the schema sidebar and steps through the Tables and Relationships panels." />
:::note[Planned]
A fuller session journal — a scrollable, richly rendered log of the whole
session that you can save as Markdown — and multiple result tabs are planned
and not yet available.
:::