2
3// Ausgelagerte MΓΌnz-Datenbank
4const COIN_DATABASE = [
5 {
6 id: "de-2006",
432
433 <script>
434 const coinDatabase = ${JSON.stringify(COIN_DATABASE)};
435 let collection = JSON.parse(localStorage.getItem('numisCollection_v03')) || [];
436
454 grid.innerHTML = '';
455
456 coinDatabase.forEach(coin => {
457 const item = document.createElement('div');
458 item.className = 'catalog-item';
564
565 window.saveCoin = function(coinId) {
566 const coinData = coinDatabase.find(c => c.id === coinId);
567 const mintEl = document.getElementById(\`mint-\${coinId}\`);
568 const commentEl = document.getElementById(\`comment-\${coinId}\`);
78
79- What about LLM payments where it can be variablea
80- What about vms/storage/databases like ec2 or s3 or supabase?
81
82---
73**Beeminder**: every goal hit POSTs a +1 datapoint to my Beeminder `burpees` goal. If the cumulative line falls below the yellow brick road, I lose money. This is the actual forcing function.
74
75**Fatebook**: every morning the system creates a prediction β *"Will I do N burpees on [date]?"* β with the model's probability as the forecast. The next morning it auto-resolves YES or NO from the database. Over time this tells me if the model is well-calibrated.
76
77## The stack
23- Optimistic updates
24- Server-side data injection
25- Type-safe database operations
26
27## Project Structure
29```
30βββ backend/ # Hono server running on Val Town
31β βββ database/ # Drizzle schema, migrations, and queries
32β βββ index.ts # Main Hono application
33βββ frontend/ # React app running in browser
4
5* `index.ts` - this is the **entrypoint** for this whole project
6* `database/` - this contains the code for interfacing with the app's SQLite database table
7
8## Hono
26## CRUD API Routes
27
28This app has two CRUD API routes: for reading and inserting into the messages table. They both speak JSON, which is standard. They import their functions from `/backend/database/queries.ts`. These routes are called from the React app to refresh and update data.
29
30## Errors
1# Database
2
3This app uses [Val Town SQLite](https://docs.val.town/std/sqlite/) to manage data. Every Val Town account comes with a free SQLite database, hosted on [Turso](https://turso.tech/). This folder is broken up into two files:
4
5* `migrations.ts` - code to set up the database tables the app needs
6* `queries.ts` - functions to run queries against those tables, which are imported and used in the main Hono server in `/backend/index.ts`
7
8## Migrations
9
10In `backend/database/migrations.ts`, this app creates a new SQLite table `reactHonoStarter_messages` to store messages.
11
12This "migration" runs once on every app startup because it's imported in `index.ts`. You can comment this line out for a slight (30ms) performance improvement on cold starts. It's left in so that users who fork this project will have the migration run correctly.
13
14SQLite has much more limited support for altering existing tables as compared to other databases. Often it's easier to create new tables with the schema you want, and then copy the data over. Happily LLMs are quite good at those sort of database operations, but please reach out in the [Val Town Discord](https://discord.com/invite/dHv45uN5RY) if you need help.
15
16## Queries
17
18The queries file is where running the migrations happen in this app. It'd also be reasonable for that to happen in index.ts, or as is said above, for that line to be commented out, and only run when actual changes are made to your database schema.
19
20The queries file exports functions to get and write data. It relies on shared types and data imported from the `/shared` directory.
4import { createTables } from "./migrations.ts";
5
6// This will create the database table if it doesn't exist.
7// This will run every time the app starts up. You can
8// comment out this line for a modest (30ms) performance improvement
9// on cold starts. It's left in to ensure the database tables are
10// automatically set up correctly for users who fork this app.
11
3
4export async function createTables() {
5 // Uncomment to reset database
6 await db.run(sql`DROP TABLE IF EXISTS messages`);
7 // Create messages table
1import { parseProject, readFile, serveFile } from "https://esm.town/v/std/utils/index.ts";
2import { Hono } from "npm:hono";
3import { getMessages, insertMessage } from "./database/queries.ts";
4
5const app = new Hono();
14 mergeUsers,
15 stopTimerSession,
16} from "../database/admin-queries.ts";
17import { getConfig, setConfig } from "../database/config-queries.ts";
18
19const adminApp = new Hono();