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
22 saveWeeklyReview,
23 updateTaskStatus,
24} from "./database/queries.ts";
25
26import { formatDate, getCurrentDay, getCurrentWeek } from "../shared/utils.ts";
27import { generateWeeklyReview, getDailyStandupFeedback, getQuickGuidance, getTrackGuidance } from "./ai/processor.ts";
28import { seedDatabase } from "./database/seeder.ts";
29
30// Create Hono app
39 if (!initialized) {
40 try {
41 await seedDatabase(import.meta.url);
42 initialized = true;
43 } catch (error) {
44 console.error("Error initializing database:", error);
45 }
46 }
42โ โโโ ai/
43โ โ โโโ processor.ts # AI integration for guidance
44โ โโโ database/
45โ โ โโโ migrations.ts # Database schema
46โ โ โโโ queries.ts # Database queries
47โ โ โโโ seeder.ts # Initial data seeding
48โ โโโ resources/
2
3/**
4 * Initialize database schema for 21-Day Survival Plan Tracker
5 */
6export const initializeDatabase = async () => {
7 // Create personal_status table
8 await sqlite.execute(`
2import { crypto } from "https://deno.land/std/crypto/mod.ts";
3
4// Types for database models
5export interface PersonalStatus {
6 id?: number;
1/**
2 * Database seeder - populates the database with initial data
3 */
4
5import { crypto } from "https://deno.land/std/crypto/mod.ts";
6import { parseSurvivalPlan, getCurrentDay, getCurrentWeek, formatDate } from "../../shared/utils.ts";
7import { initializeDatabase } from "./migrations.ts";
8import {
9 saveTask,
13} from "./queries.ts";
14
15// Main seeder function - initializes the database and populates it with tasks
16export const seedDatabase = async (importMetaUrl: string): Promise<void> => {
17 // Initialize the database schema
18 await initializeDatabase();
19
20 // Seed track statuses
30 await seedDailyNonNegotiables(dailyNonNegotiables);
31
32 console.log("Database seeded successfully!");
33};
34