import { Database } from "bun:sqlite"; export declare function looksLikeSqlite(bytes: Uint8Array): boolean; /** * Opens the query-only connection used by read tools, retrying read-write mode solely to initialize missing WAL sidecars. * * Helpers here run statements through `db.query()`: `close()` finalizes that cache, while an * unfinalized `db.prepare()` statement leaves the connection a zombie that keeps the file open * (Windows then refuses to delete it). */ export declare function openSqliteReadConnection(filePath: string): Promise; /** Row cap for raw `?q=` SQL — protects against `SELECT *` on multi-million-row tables. */ export declare const MAX_RAW_QUERY_ROWS = 1000; export interface SqlitePathCandidate { sqlitePath: string; subPath: string; queryString: string; } export type SqliteSelector = { kind: "list"; } | { kind: "schema"; table: string; sampleLimit: number; } | { kind: "row"; table: string; key: string; } | { kind: "query"; table: string; limit: number; offset: number; order?: string; where?: string; } /** `page` is set when `limit` or `offset` pages the query's rows, as they page a table. */ | { kind: "raw"; sql: string; page?: { limit: number; offset: number; }; }; export type SqliteRowLookup = { kind: "pk"; column: string; type: string; } | { kind: "rowid"; }; /** * Row count for a table in the listing. * - `exact`: counted in full (the table is small enough to count cheaply). * - `estimate`: the planner's `sqlite_stat1` figure; the table is too large to * scan, so this may be stale. * - `atLeast`: a lower bound; counting was capped before reaching the end. */ export type TableRowCount = { kind: "exact"; rows: number; } | { kind: "estimate"; rows: number; } | { kind: "atLeast"; rows: number; }; export interface SqliteTableSummary { name: string; count: TableRowCount; } export declare function parseSqlitePathCandidates(filePath: string): SqlitePathCandidate[]; export declare function isSqliteFile(absolutePath: string): Promise; export declare function parseSqliteSelector(subPath: string, queryString: string): SqliteSelector; export declare function listTables(db: Database, options?: { probeCap?: number; }): SqliteTableSummary[]; export declare function getTableSchema(db: Database, table: string): string; export declare function getTablePrimaryKey(db: Database, table: string): { column: string; type: string; } | null; export declare function resolveTableRowLookup(db: Database, table: string): SqliteRowLookup; export declare function queryRows(db: Database, table: string, opts: { limit: number; offset: number; order?: string; where?: string; }): { columns: string[]; rows: Record[]; totalCount: number; }; export declare function getRowByKey(db: Database, table: string, pk: { column: string; type?: string; }, key: string): Record | null; export declare function getRowByRowId(db: Database, table: string, key: string): Record | null; /** * Runs a read-only SQL query. Without `page`, rows are capped at * {@link MAX_RAW_QUERY_ROWS}; with it, `offset` rows are skipped and at most * `limit` kept. `truncated` says rows remain past the ones returned. */ export declare function executeReadQuery(db: Database, sql: string, page?: { limit: number; offset: number; }): { columns: string[]; rows: Record[]; truncated: boolean; }; export declare function insertRow(db: Database, table: string, data: Record): void; export declare function updateRowByKey(db: Database, table: string, pk: { column: string; type?: string; }, key: string, data: Record): number; export declare function updateRowByRowId(db: Database, table: string, key: string, data: Record): number; export declare function deleteRowByKey(db: Database, table: string, pk: { column: string; type?: string; }, key: string): number; export declare function deleteRowByRowId(db: Database, table: string, key: string): number; export declare function renderTableList(tables: SqliteTableSummary[]): string; export declare function renderSchema(createSql: string, sampleRows: { columns: string[]; rows: Record[]; }): string; export declare function renderRow(row: Record): string; export declare function renderTable(columns: string[], rows: Record[], meta: { totalCount: number; offset: number; limit: number; table: string; dbPath: string; where?: string; order?: string; }): string;