2
3/**
4 * Retrieves all memories from the database
5 * @param includeDate Whether to include date-specific memories or not
6 * @param startDate Optional start date to filter memories from (ISO format)
6import { Hono } from "npm:hono";
7import { type Memory } from "../shared/types.ts";
8import { createMemory, deleteMemory, getAllMemories, updateMemory } from "./database/queries.ts";
9
10const app = new Hono();
34
35/**
36 * Store a chat message in the database
37 */
38export async function storeChatMessage(
130 }
131
132 console.log(`Weather forecast updated in the database.`);
133 return summary;
134}
125 }
126
127 console.log(`Calendar events imported into the database.`);
128 return events;
129 } catch (error) {
8
9/**
10 * Retrieves previously generated fun facts from the memories database
11 * @returns Array of previous fun facts
12 */
47
48/**
49 * Inserts a fun fact into the memories database
50 * @param date Date for the fun fact in ISO format
51 * @param factText The fun fact text
208```
209โโโ backend/
210โ โโโ database/
211โ โ โโโ migrations.ts # Schema definitions
212โ โ โโโ queries.ts # DB query functions
270- Handle API calls properly with proper error catching
271
272### Database Patterns
273- Run migrations on startup or comment out for performance
274- Change table names when modifying schemas rather than altering
1# iClickWolf - Val Town Edition
2
3This app is a port of the iClickWolf Next.js application to Val Town, using SQLite for database storage.
4
5## Project Structure
6
7- **Backend**: `/backend/index.ts` - The main HTTP server that serves the frontend and API endpoints
8 - `/backend/database/` - Contains SQLite database setup and queries
9 - `/backend/routes/` - API routes for checkout, webhook, and items
10
18- Stripe integration for payments
19- Email notifications for order confirmations
20- SQLite database for storing items and preorders
21
22## Environment Variables
34
35- If Stripe is not configured (missing API keys), appropriate error messages are shown
36- If the database fails to load items, default values are used as a fallback
37- All API errors are properly logged and user-friendly messages are displayed
38- Form validation prevents submission of invalid data
39
40## Database
41
42The application uses Val Town's SQLite database with the following tables:
43
44- `iclickwolf_items_v1` - Stores product information
1import { Hono } from "npm:hono";
2import { getFirstItem } from "../database/queries.ts";
3
4const app = new Hono();
9 const item = await getFirstItem();
10 if (!item) {
11 // Create a default item if none exists in the database
12 const defaultItem = {
13 id: 1,
33 image: "https://placehold.co/200x200?text=iClicker",
34 buyUrl: "",
35 error: "Database error: " + error.message
36 }, 200); // Return 200 with error in the payload so frontend can still display something
37 }
41 email,
42 pickupLocation,
43 productID: 1 // We'll get the actual ID from the database on the server
44 }),
45 });