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
1import { serveFile } from "https://esm.town/v/std/utils/index.ts";
2import { generateCode } from "./backend/generate-code.ts";
3import { createTables } from "./database/migrations.ts";
4import { createProject, getCode, getNextVersionNumber, insertVersion } from "./database/queries.ts";
5
6await createTables();
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 { initializeDatabase, cleanupExpiredSessions } from "./database/migrations.ts";
4import authRoutes from "./routes/auth.ts";
5import mediaRoutes from "./routes/media.ts";
12});
13
14// Initialize database on startup
15await initializeDatabase();
16
17// Clean up expired sessions periodically
8 createSearchHistory,
9 deleteMediaAnalysis
10} from "../database/queries.ts";
11import {
12 analyzeImage,
88 }
89
90 // Save analysis to database
91 const mediaAnalysis = await createMediaAnalysis(
92 user.id,
6 getUserPasswordHash,
7 deleteUserSessions
8} from "../database/queries.ts";
9import {
10 hashPassword,
2import { sign, verify } from "https://esm.sh/jsonwebtoken@9.0.2";
3import { hash, compare } from "https://esm.sh/bcryptjs@2.4.3";
4import { getUserById, validateSession, createSession, deleteSession } from "../database/queries.ts";
5import type { User } from "../../shared/types.ts";
6
1import { sqlite } from "https://esm.town/v/stevekrouse/sqlite";
2
3// Database schema definitions and migrations
4
5export async function initializeDatabase() {
6 // Users table
7 await sqlite.execute(`
79 `);
80
81 console.log('Database initialized successfully');
82}
83
16### Backend (`/backend/`)
17- **index.ts**: Main Hono server with API routes
18- **database/**: SQLite database setup and queries
19- **routes/**: Modular route handlers
20- **auth/**: Authentication middleware and utilities
54 - `JWT_SECRET`: Secret for JWT token signing
55
562. The application will automatically create database tables on first run
57
583. Access the application at the HTTP endpoint URL
8 getUserByBearerToken,
9 updateBearerTokenLastUsed,
10} from "../database/queries.ts";
11import { requireAuth } from "./auth.ts";
12
141});
142
143// Debug endpoint to test database
144content.get("/debug", async (c) => {
145 try {