use lowdb for faster iteration; use strings for ids and camelCase for field names for consistency

This commit is contained in:
Avraham Sakal
2025-07-27 09:46:34 -04:00
parent 1f80ad4ba9
commit 01d2997f77
9 changed files with 134 additions and 88 deletions
+30
View File
@@ -0,0 +1,30 @@
import { Low } from "lowdb";
import { JSONFile } from "lowdb/node";
export type Conversation = {
id: string;
title: string;
userId: string;
};
type DB = {
conversations: Array<Conversation>;
messages: Array<{
id: string;
conversationId: string;
content: string;
role: "user" | "assistant" | "system" | "data";
index: number;
createdAt: string;
runningSummary?: string;
}>;
};
export const db = new Low<DB>(new JSONFile("db.json"), {
conversations: [],
messages: [],
});
/** Initialize the database. Sets `db.data` to the default state if the file doesn't exist. */
await db.read();
/** Write the database to the file, in case it didn't exist before. */
await db.write();