summaryrefslogtreecommitdiffhomepage
path: root/packages/core/src/db
diff options
context:
space:
mode:
Diffstat (limited to 'packages/core/src/db')
-rw-r--r--packages/core/src/db/messages.ts26
-rw-r--r--packages/core/src/db/settings.ts4
2 files changed, 25 insertions, 5 deletions
diff --git a/packages/core/src/db/messages.ts b/packages/core/src/db/messages.ts
index 5a8758f..80a1f22 100644
--- a/packages/core/src/db/messages.ts
+++ b/packages/core/src/db/messages.ts
@@ -10,14 +10,30 @@ export interface MessageRow {
createdAt: number;
}
-export function appendMessage(tabId: string, id: string, role: string, contentJson: string, thinking?: string): void {
+export function appendMessage(
+ tabId: string,
+ id: string,
+ role: string,
+ contentJson: string,
+ thinking?: string,
+): void {
const db = getDatabase();
- const maxSeq = db.query("SELECT COALESCE(MAX(seq), -1) as max_seq FROM messages WHERE tab_id = $tabId").get({ $tabId: tabId }) as { max_seq: number };
+ const maxSeq = db
+ .query("SELECT COALESCE(MAX(seq), -1) as max_seq FROM messages WHERE tab_id = $tabId")
+ .get({ $tabId: tabId }) as { max_seq: number };
const seq = (maxSeq?.max_seq ?? -1) + 1;
db.query(
`INSERT INTO messages (id, tab_id, seq, role, content_json, thinking, created_at)
VALUES ($id, $tabId, $seq, $role, $contentJson, $thinking, $now)`,
- ).run({ $id: id, $tabId: tabId, $seq: seq, $role: role, $contentJson: contentJson, $thinking: thinking ?? null, $now: Date.now() });
+ ).run({
+ $id: id,
+ $tabId: tabId,
+ $seq: seq,
+ $role: role,
+ $contentJson: contentJson,
+ $thinking: thinking ?? null,
+ $now: Date.now(),
+ });
}
export function updateMessage(id: string, contentJson: string, thinking?: string): void {
@@ -29,7 +45,9 @@ export function updateMessage(id: string, contentJson: string, thinking?: string
export function getMessagesForTab(tabId: string): MessageRow[] {
const db = getDatabase();
- const rows = db.query("SELECT * FROM messages WHERE tab_id = $tabId ORDER BY seq ASC").all({ $tabId: tabId }) as Array<Record<string, unknown>>;
+ const rows = db
+ .query("SELECT * FROM messages WHERE tab_id = $tabId ORDER BY seq ASC")
+ .all({ $tabId: tabId }) as Array<Record<string, unknown>>;
return rows.map((row) => ({
id: row.id as string,
tabId: row.tab_id as string,
diff --git a/packages/core/src/db/settings.ts b/packages/core/src/db/settings.ts
index 51d6ea2..f9d152e 100644
--- a/packages/core/src/db/settings.ts
+++ b/packages/core/src/db/settings.ts
@@ -2,7 +2,9 @@ import { getDatabase } from "./index.js";
export function getSetting(key: string): string | null {
const db = getDatabase();
- const row = db.query("SELECT value FROM settings WHERE key = $key").get({ $key: key }) as { value: string } | null;
+ const row = db.query("SELECT value FROM settings WHERE key = $key").get({ $key: key }) as {
+ value: string;
+ } | null;
return row?.value ?? null;
}