11});
12
13app.get("/clear-databases", async (c) => {
14 return c.html(`
15 <h1>Clear Databases</h1>
16 <p>This will clear the databases for the bot.</p>
17 <form method="post" action="/clear-databases">
18 <input type="text" name="token" placeholder="Token" />
19 <button type="submit">Clear Databases</button>
20 </form>
21 <p>The password is ${Deno.env.get("ADMIN_TOKEN")}</p>
23});
24
25// Clear databases endpoint
26app.post("/clear-databases", async (c) => {
27 const body = await c.req.parseBody();
28 const token = body["token"];
32 }
33
34 // clear the databases
35 await sqlite.execute(`DELETE FROM ${LangChainTables.checkpoints}`);
36 await sqlite.execute(`DELETE FROM ${LangChainTables.checkpoint_writes}`);
37
38 return c.json({ message: "Databases cleared" });
39});
40
40 await ctx.reply(`✅ Successfully joined room with secret: ${roomSecret}`);
41 } catch (dbError) {
42 console.error("Database error in join command:", dbError);
43 await ctx.reply("❌ Error joining room. Please try again.");
44 }
74 await ctx.reply(`✅ Successfully left room with secret: ${roomSecret}`);
75 } catch (dbError) {
76 console.error("Database error in leave command:", dbError);
77 await ctx.reply("❌ Error leaving room. Please try again.");
78 }
45 await new Promise(res => setTimeout(res, getRandomInt(200, 400)));
46 const possibleLogs = [
47 `ERROR: Connection to database 'pg-primary-01' on host ${serviceName}-db-host timed out.`,
48 `WARN: High memory pressure detected on service '${serviceName}'. Throttling new connections.`,
49 `ERROR: Failed to acquire lock 'payment_processing_lock' for service ${serviceName}.`,
170async function safetyCheckerAgent(acp: ACP): Promise<ACP> {
171 const { remediation_plan } = acp.payload.content;
172 const dangerousCommands = ["reboot", "rm -rf", "shutdown", "DROP DATABASE", "DELETE FROM"];
173
174 const unsafeStep = remediation_plan.find(step =>
16- Supports both general attendee registration and speaker applications
17- Collects attendee interests and preferences for event content
18- SQLite database storage for all submissions
19- Email notifications for new submissions
20- Mobile-responsive design
69- Copy the entire list to clipboard with one click
70
71## Database Schema
72
73```sql
16 { name: "Farcaster SDK", path: "/" },
17 { name: "Haptics", path: "/haptics" },
18 { name: "Database", path: "/db" },
19 { name: "About", path: "/about" },
20 ];
39 <Route path="/" element={<FarcasterMiniApp />} />
40 <Route path="/haptics" element={<CustomHaptics />} />
41 <Route path="/db" element={<Database />} />
42 <Route path="/about" element={<About />} />
43 <Route path="/neynar" element={<Neynar />} />
55 <div className="">✷ Hono + React + Tailwind</div>
56 <div className="">✷ React Router + React Query</div>
57 <div className="">✷ Built-in database (blob storage)</div>
58 <div className="">✷ Farcaster mini app manifest + webhook + embed metadata</div>
59 <div className="">✷ Farcaster notifications (storing tokens, sending recurring notifications, ...)</div>
71}
72
73function Database() {
74 const queryFn = () => fetch("/api/counter/get").then((r) => r.json());
75 const { data, refetch } = useQuery({ queryKey: ["counter"], queryFn });
76 return (
77 <Section className="flex flex-col items-start gap-3 m-5">
78 {/* <h2 className="font-semibold">Database Example</h2> */}
79 <div className="">Counter value: {data}</div>
80 <Button variant="outline" onClick={() => fetch("/api/counter/increment").then(refetch)}>
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.
3import { createTables, tableName } from "./migrations.ts";
4
5// This will create the database table if it doesn't exist.
6// This will run every time the app starts up. You can
7// comment out this line for a modest (30ms) perforamnce improvement
8// on cold starts. It's left in to ensure the database tables are
9// automatically set up correctly for users who fork this app.
10await createTables();
13
14 However, you should know that SQLite has much more limited
15 support for altering existing tables as compared to other databases.
16 Often it's easier to create new tables with the schema you want, and then
17 copy the data over. */
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();