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 <noreply@anthropic.com>
This commit is contained in:
parent
3d0519db8f
commit
df3bddeaeb
1 changed files with 21 additions and 1 deletions
|
|
@ -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<string, unknown>[];
|
||||
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<string, unknown>[];
|
||||
}
|
||||
|
||||
const elapsed = Date.now() - startTime;
|
||||
this.historyManager?.addEntry(executedSql, elapsed, rows.length);
|
||||
|
||||
this.lastRows = rows;
|
||||
this.lastKeys = rows.length > 0 ? Object.keys(rows[0]) : [];
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue