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) {
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
548 }
549 const domain = payload.policyDomain.toLowerCase();
550 // Mock Database / Retrieval Logic
551 const mockKB = {
552 "environmental": [
46 }
47
48 // Now it's time to upload things to database and blob storage
49 // First, add to database, and get the ID
50 const id = await sqlite.execute(
51 `INSERT INTO ${TABLE_NAME} (title, data, type, time) VALUES ($title, $data, $type, CURRENT_TIMESTAMP)`,
1import { Hono } from "npm:hono";
2import { createThread, getThreadMessages, getUserThreads } from "../database/queries.ts";
3
4const app = new Hono();
3import { type Message, type Thread, type User } from "../../shared/types.ts";
4import {
5 type DatabaseMessage,
6 type DatabaseThread,
7 type DatabaseUser,
8 MESSAGES_TABLE,
9 THREADS_TABLE,
11} from "./schema.ts";
12
13function parseDatabaseUser(user: DatabaseUser): User {
14 return {
15 id: user.id,
21}
22
23function parseDatabaseThread(thread: DatabaseThread): Thread {
24 return {
25 id: thread.id,
32}
33
34function parseDatabaseMessage(message: DatabaseMessage): Message {
35 return {
36 id: message.id,
60 );
61 if (result.rows && result.rows.length > 0) {
62 return parseDatabaseUser(result.rows[0]);
63 }
64
78 );
79 if (result2.rows && result2.rows.length > 0) {
80 return parseDatabaseUser(result2.rows[0]);
81 }
82
90 );
91 if (result3.rows && result3.rows.length > 0) {
92 return parseDatabaseUser(result3.rows[0]);
93 }
94 throw new Error("Failed to create user");
126
127 if (result.rows && result.rows.length > 0) {
128 return parseDatabaseThread(result.rows[0]);
129 }
130 return null;
136 [userId],
137 );
138 return (result.rows || []).map(parseDatabaseThread);
139}
140
144 [valId],
145 );
146 return (result.rows || []).map(parseDatabaseThread);
147}
148
155 );
156
157 return (result.rows || []).map(parseDatabaseMessage);
158}
159