LCOV - code coverage report
Current view: top level - dashql-app/src/views/query_result - format_peek.ts Coverage Total Hit
Test: DashQL 915828b Lines: 100.0 % 15 15
Test Date: 2026-11-06 19:30:32

            Line data    Source code
       1              : import { detectPlanEngine } from '../query_profile/plan_engine.js';
       2              : 
       3              : export type FormatHint = 'array' | 'struct' | 'json' | 'sql' | 'plan' | null;
       4              : 
       5              : /// Values can be megabytes large, only look at the first and last characters
       6            1 : const PEEK_WINDOW = 4096;
       7            1 : const SQL_RE = /^\s*(SELECT|INSERT|UPDATE|DELETE|CREATE|ALTER|DROP|WITH|EXPLAIN|COPY|SET|BEGIN|COMMIT|ROLLBACK)\b/i;
       8              : 
       9            1 : export function peekFormat(value: string | null): FormatHint {
      10            1 :     if (value == null || value.length < 2) return null;
      11            1 :     const head = value.slice(0, PEEK_WINDOW).trimStart();
      12            1 :     const tail = value.slice(-PEEK_WINDOW).trimEnd();
      13            1 :     const first = head.length > 0 ? head[0] : null;
      14            1 :     const last = tail.length > 0 ? tail[tail.length - 1] : null;
      15            1 :     if ((first === '{' || first === '[') && (last === '}' || last === ']')) {
      16              :         // A plan of an engine (Hyper, Trino)
      17            1 :         if (detectPlanEngine(value) != null) return 'plan';
      18            1 :         return 'json';
      19            1 :     }
      20            1 :     if (SQL_RE.test(head)) return 'sql';
      21            1 :     return null;
      22            1 : }
        

Generated by: LCOV version 2.0-1