Fix db types
This commit is contained in:
parent
0a17b61bf3
commit
b28283bf34
1 changed files with 20 additions and 6 deletions
26
src/db.ts
26
src/db.ts
|
|
@ -3,6 +3,17 @@
|
|||
import { Database } from "bun:sqlite";
|
||||
import type { Device, OutputLog, PromptData, Session } from "./types";
|
||||
|
||||
// Raw row returned from SQLite before JSON parsing
|
||||
interface RawPromptRow {
|
||||
id: number;
|
||||
session_id: number;
|
||||
created_at: number;
|
||||
prompt_text: string;
|
||||
response: string | null;
|
||||
responded_at: number | null;
|
||||
prompt_json: string | null;
|
||||
}
|
||||
|
||||
// Extend Prompt interface to include prompt_json field
|
||||
export interface Prompt {
|
||||
id: number;
|
||||
|
|
@ -58,9 +69,12 @@ function runMigrations(): void {
|
|||
for (const migration of migrations) {
|
||||
try {
|
||||
db.exec(migration);
|
||||
} catch (error: any) {
|
||||
} catch (error: unknown) {
|
||||
// Ignore "duplicate column" errors - column already exists
|
||||
if (!error.message?.includes("duplicate column")) {
|
||||
if (
|
||||
!(error instanceof Error) ||
|
||||
!error.message?.includes("duplicate column")
|
||||
) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
|
@ -221,7 +235,7 @@ export function createPrompt(
|
|||
promptText,
|
||||
promptJson ?? null,
|
||||
);
|
||||
const prompt = row as any;
|
||||
const prompt = row as RawPromptRow;
|
||||
|
||||
// Parse prompt_json if present
|
||||
if (prompt.prompt_json) {
|
||||
|
|
@ -239,7 +253,7 @@ export function getPrompt(promptId: number): Prompt | null {
|
|||
const row = getPromptStmt.get(promptId);
|
||||
if (!row) return null;
|
||||
|
||||
const prompt = row as any;
|
||||
const prompt = row as RawPromptRow;
|
||||
|
||||
// Parse prompt_json if present
|
||||
if (prompt.prompt_json) {
|
||||
|
|
@ -258,9 +272,9 @@ export function respondToPrompt(promptId: number, response: string): void {
|
|||
}
|
||||
|
||||
export function getPendingPrompts(): Prompt[] {
|
||||
const rows = getPendingPromptsStmt.all();
|
||||
const rows = getPendingPromptsStmt.all() as RawPromptRow[];
|
||||
|
||||
return rows.map((row: any) => {
|
||||
return rows.map((row) => {
|
||||
// Parse prompt_json if present
|
||||
if (row.prompt_json) {
|
||||
try {
|
||||
|
|
|
|||
Loading…
Reference in a new issue