OpenTowniesystem_prompt.txt2 matches
166```
167โโโ backend/
168โ โโโ database/
169โ โ โโโ migrations.ts # Schema definitions
170โ โ โโโ queries.ts # DB query functions
228- Handle API calls properly with proper error catching
229230### Database Patterns
231- Run migrations on startup or comment out for performance
232- Change table names when modifying schemas rather than altering
reactHonoExampleREADME.md2 matches
45* `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
78## Hono
26## CRUD API Routes
2728This 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.
2930## Errors
reactHonoExampleREADME.md6 matches
1# Database
23This 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:
45* `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`
78## Migrations
910In `backend/database/migrations.ts`, this app creates a new SQLite table `reactHonoStarter_messages` to store messages.
1112This "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.
1314SQLite 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.
1516## Queries
1718The 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.
1920The queries file exports functions to get and write data. It relies on shared types and data imported from the `/shared` directory.
reactHonoExamplequeries.ts2 matches
3import { createTables, tableName } from "./migrations.ts";
45// 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();
1314However, you should know that SQLite has much more limited
15support for altering existing tables as compared to other databases.
16Often it's easier to create new tables with the schema you want, and then
17copy the data over. */
reactHonoExampleindex.ts1 match
2import { readFile, servePublicFile } from "https://esm.town/v/stevekrouse/utils@187-main/serve-public/index.ts";
3import { Hono } from "npm:hono";
4import { getMessages, insertMessage } from "./database/queries.ts";
56const app = new Hono();
499const KEY = "windsurf_projectContext";
500501// Initialize database
502await sqlite.execute(`
503CREATE TABLE IF NOT EXISTS ${KEY}_project_state_${SCHEMA_VERSION} (
cerebras_coderindex2 matches
1import { generateCode } from "./backend/generate-code";
2import { createTables } from "./database/migrations";
3import { createProject, getCode, getNextVersionNumber, insertVersion } from "./database/queries";
45async function servePublicFile(path: string): Promise<Response> {
AlwaysHereBackendindex.ts1 match
28updateFriendRequestStatus,
29updateUser,
30} from "./database/queries.ts";
3132const app = new Hono();
EchoPromptermain.tsx8 matches
940const openai = new OpenAI();
941942// Use the val's URL as a unique key for database tables
943const KEY = "EchoPrompter";
944945// Initialize database tables
946await sqlite.execute(`
947CREATE TABLE IF NOT EXISTS ${KEY}_agents (
976});
977} catch (error) {
978console.error("Database error:", error);
979return new Response(
980JSON.stringify({ error: "Failed to fetch recent agents" }),
1172}
11731174// Insert into database with commands
1175const result = await sqlite.execute(
1176`INSERT INTO ${KEY}_agents (name, description, prompt, commands) VALUES (?, ?, ?, ?)`,
1212const { agentId, message, history } = await request.json();
12131214// Get agent from database
1215const agentResult = await sqlite.execute(
1216`SELECT * FROM ${KEY}_agents WHERE id = ?`,
1262const response = completion.choices[0].message.content;
12631264// Log conversation in database
1265await sqlite.execute(
1266`INSERT INTO ${KEY}_conversations (agent_id, user_message, assistant_response) VALUES (?, ?, ?)`,
1291const { agentId, command, inputs, history } = await request.json();
12921293// Get agent from database
1294const agentResult = await sqlite.execute(
1295`SELECT * FROM ${KEY}_agents WHERE id = ?`,
1475}
14761477async function initDatabase(db) {
1478// Create agents table if not exists
1479await db.execute(`