The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 06:00 UTC
| 1 | import { defineScene } from "../capture/scene.ts"; |
| 2 | |
| 3 | export default defineScene({ |
| 4 | title: "Store links in D1", |
| 5 | chapter: "02-d1", |
| 6 | notes: |
| 7 | "A D1 database with a migrations folder. yield* Cloudflare.D1.QueryDatabase(Db) is the binding: it grants this one database to this one Worker, with no account token shipped. Effect SQL on top. alchemy dev applied the migration to the local D1, and short links now redirect.", |
| 8 | async run(s) { |
| 9 | await s.sync({ except: ["migrations/0001_links.sql", "src/Db.ts", "src/Api.ts"] }); |
| 10 | await s.editor.show("migrations/0001_links.sql"); |
| 11 | s.pause(0.5); |
| 12 | await s.editor.show("src/Db.ts"); |
| 13 | s.pause(0.5); |
| 14 | await s.editor.show("src/Api.ts"); |
| 15 | s.pause(1); |
| 16 | |
| 17 | await s.terminal(async (t) => { |
| 18 | await t.waitDev(); |
| 19 | await t.sleep(800); |
| 20 | await t.run( |
| 21 | "deploy", |
| 22 | `CODE=$(curl -s --json '{"url":"https://alchemy.run"}' localhost:1337/links | jq -r .code)`, |
| 23 | ); |
| 24 | await t.run( |
| 25 | "deploy", |
| 26 | `curl -s -o /dev/null -w '%{http_code} → %{redirect_url}\\n' localhost:1337/$CODE`, |
| 27 | ); |
| 28 | }); |
| 29 | |
| 30 | await s.diagram({ stage: `dev_${process.env.USER}`, nodes: ["Db"], edges: ["Api->Db"] }); |
| 31 | s.pause(1); |
| 32 | await s.browser.open("http://localhost:5173", { waitFor: /alchemy\.run/ }); |
| 33 | s.pause(1.5); |
| 34 | }, |
| 35 | }); |