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
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/schema.ts';
4import {
5 createUser,
12 getSession,
13 deleteSession
14} from './database/users.ts';
15import {
16 createArtwork,
22 searchArtworks,
23 getArtworkCountByUserId
24} from './database/artworks.ts';
25import {
26 hashPassword,
36const app = new Hono();
37
38// Initialize database on startup
39initializeDatabase().catch(console.error);
40
41// Clean up expired sessions periodically
1import { sqlite } from "https://esm.town/v/stevekrouse/sqlite";
2
3// Database table names with versioning for schema changes
4export const TABLES = {
5 USERS: 'pixelart_users_v1',
8};
9
10// Initialize database tables
11export async function initializeDatabase() {
12 try {
13 // Users table
64 await sqlite.execute(`CREATE INDEX IF NOT EXISTS idx_sessions_expires_at ON ${TABLES.SESSIONS}(expires_at)`);
65
66 console.log('Database initialized successfully');
67 } catch (error) {
68 console.error('Error initializing database:', error);
69 throw error;
70 }
1import { Hono } from "https://esm.sh/hono@3.11.7";
2import { sqlite } from "https://esm.town/v/stevekrouse/sqlite";
3import { getAllTools, getToolsByCategory, searchTools, getFeaturedTools, getToolStats } from "../database/queries.ts";
4import { CATEGORIES } from "../../shared/types.ts";
5