From df3bddeaebdb376325e6b35592e0120830f3f62f Mon Sep 17 00:00:00 2001 From: tolvitty Date: Thu, 12 Feb 2026 11:24:20 +0100 Subject: [PATCH] QueryModal: History-Integration und initiale SQL Query-Editor trackt jetzt alle Ausfuehrungen im HistoryManager (Laufzeit, Zeilenanzahl). Akzeptiert optionale initiale SQL fuer Template- und Favoriten-Integration. Co-Authored-By: Claude Opus 4.6 --- src/query/query-modal.ts | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/query/query-modal.ts b/src/query/query-modal.ts index e399a5e..db2973a 100644 --- a/src/query/query-modal.ts +++ b/src/query/query-modal.ts @@ -3,15 +3,20 @@ import { QueryConfig, TimeRange, EventType } from '../types'; import { buildQuery } from '../core/query-builder'; import { DatabaseManager } from '../core/database'; import { renderTable, toMarkdownTable } from '../viz/table-renderer'; +import { HistoryManager } from '../management/history'; export class QueryModal extends Modal { private editorEl!: HTMLTextAreaElement; private resultEl!: HTMLElement; private modeToggle!: HTMLButtonElement; private mode: 'shorthand' | 'sql' = 'shorthand'; + private historyManager?: HistoryManager; + private initialSql?: string; - constructor(app: App, private db: DatabaseManager) { + constructor(app: App, private db: DatabaseManager, historyManager?: HistoryManager, initialSql?: string) { super(app); + this.historyManager = historyManager; + this.initialSql = initialSql; } onOpen(): void { @@ -76,6 +81,14 @@ export class QueryModal extends Modal { // Results this.resultEl = contentEl.createDiv({ cls: 'logfire-qm-results' }); + + // Initial SQL setzen + if (this.initialSql) { + this.mode = 'sql'; + this.modeToggle.textContent = 'Modus: SQL'; + this.editorEl.value = this.initialSql; + this.editorEl.placeholder = 'SELECT * FROM events\nWHERE type = \'file:create\'\nORDER BY timestamp DESC\nLIMIT 50'; + } } onClose(): void { @@ -91,8 +104,11 @@ export class QueryModal extends Modal { this.resultEl.empty(); + const startTime = Date.now(); + try { let rows: Record[]; + let executedSql = input; if (this.mode === 'sql') { // Raw SQL mode @@ -109,9 +125,13 @@ export class QueryModal extends Modal { // Shorthand mode const config = parseShorthand(input); const { sql, params } = buildQuery(config); + executedSql = sql; rows = this.db.queryReadOnly(sql, params) as Record[]; } + const elapsed = Date.now() - startTime; + this.historyManager?.addEntry(executedSql, elapsed, rows.length); + this.lastRows = rows; this.lastKeys = rows.length > 0 ? Object.keys(rows[0]) : [];