Project Files
src / utils / excel / excelPreview.ts
// excel/excelPreview.ts
import type { FileHandle } from "@lmstudio/sdk";
import { getOrCreateDb, queryAll } from "../../tools/excel/buildExcelTools";
const previewCache = new Map<string, string>();
export async function makeExcelPreview(file: FileHandle): Promise<string> {
const cached = previewCache.get(file.name);
if (cached) return cached;
const db = await getOrCreateDb(file);
const tables = await queryAll(db, `SELECT table_name FROM information_schema.tables WHERE table_schema='main'`);
const parts = await Promise.all(
tables.map(async (t: any) => {
const cols = await queryAll(db, `PRAGMA table_info("${t.table_name}")`);
return `${t.table_name}(${cols.map((c: any) => c.name).join(", ")})`;
})
);
const preview = `Tables: ${parts.join("; ")}`;
previewCache.set(file.name, preview);
return preview;
}