21## Further resources
22
23- [React Hono Example](https://www.val.town/x/stevekrouse/reactHonoExample) is a bigger example project, with a SQLite database table, queries, client-side CSS, a favicon, and shared code that runs on both client and server.
21## Further resources
22
23- [React Hono Example](https://www.val.town/x/stevekrouse/reactHonoExample) is a bigger example project, with a SQLite database table, queries, client-side CSS, a favicon, and shared code that runs on both client and server.
4 serveFile,
5} from "https://esm.town/v/std/utils@85-main/index.ts";
6import { runMigrations } from "./database/migrations.ts";
7import {
8 getActiveUsers,
22 getLeaderboard,
23 clearAllGameData,
24} from "./database/queries.ts";
25import type { User, GameState } from "../shared/types.ts";
26
32});
33
34// Initialize database
35await runMigrations();
36
51โโโ backend/
52โ โโโ index.ts # Main Hono server with game API endpoints
53โ โโโ database/
54โ โ โโโ migrations.ts # SQLite schema for users, facts, votes, rounds
55โ โ โโโ queries.ts # Database query functions for game logic
56โ โโโ routes/
57โ โโโ websocket.ts # WebSocket connection handling (future)
198```
199โโโ backend/
200โ โโโ database/
201โ โ โโโ migrations.ts # Schema definitions
202โ โ โโโ queries.ts # DB query functions
257 ```
258
259### Database Patterns
260- Run migrations on startup or comment out for performance
261- Change table names when modifying schemas rather than altering
245 if (!response.ok) {
246 if (response.status === 404) {
247 return c.json({ error: "BIN not found in database" }, 404);
248 }
249 throw new Error(`BIN lookup service error: ${response.status}`);
294app.get("/api/marketplace/products", async c => {
295 try {
296 // In a real application, this would fetch from a database
297 const products = [
298 {
373 const id = c.req.param("id");
374
375 // In a real application, this would fetch from a database
376 const products = [
377 {
430 }
431
432 // In a real application, this would send an email or save to database
433 // For now, we'll just return success and redirect to Telegram
434
307 const pathParts = url.pathname.split("/").filter(p => p.trim() !== "");
308
309 // API endpoints - proxy to the main Shitty database
310 if (pathParts[0] === "api" && pathParts.length >= 2) {
311 const syncId = pathParts[1];
355 }
356
357 // Helper to get instance data from the main shitty database
358 async function getInstanceData(currentSyncId: string) {
359 // Return demo data for demo instance
12 listCachedPlants,
13 type PlantInfo,
14} from "./backend/database/cache.ts";
15
16const app = new Hono();
136 example: "/plant/rose",
137 testPage: "/ - Simple testing interface",
138 adminPage: "/admin - Cache database admin interface (requires login)",
139 loginPage: "/login - Admin login",
140 cache: cacheInfo,
147});
148
149// Admin page to view cache database - requires authentication
150app.get("/admin", requireAuth, async (c) => {
151 const html = await readFile("/admin.html", import.meta.url);
274});
275
276// Test database endpoint
277app.get("/test-db", async (c) => {
278 try {
279 console.log("Testing database connection...");
280
281 // Test basic SQLite functionality
296
297 return c.json({
298 message: "Database test successful",
299 testResult,
300 selectResult,
301 });
302 } catch (error) {
303 console.error("Database test failed:", error);
304 return c.json({
305 error: "Database test failed",
306 details: error instanceof Error ? error.message : "Unknown error",
307 }, 500);
1import { Hono } from "https://esm.sh/hono@3.11.7";
2import type { GameState, Player, MoveRequest, GameResponse, GamesListResponse } from "../../shared/types.ts";
3import { createGame, getGame, updateGame, getRecentGames } from "../database/queries.ts";
4
5const app = new Hono();
1import { Hono } from "https://esm.sh/hono@3.11.7";
2import { readFile, serveFile } from "https://esm.town/v/std/utils@85-main/index.ts";
3import { runMigrations } from "./database/migrations.ts";
4import gameRoutes from "./routes/game.ts";
5
11});
12
13// Initialize database
14await runMigrations();
15