mirror of
https://github.com/Kaelio/ktx.git
synced 2026-06-07 07:55:13 +02:00
* feat(context): add warehouse dialect dispatch * feat(context): read warehouse scan catalog * feat(context): add entity details verification tool * feat(context): add ingest SQL verification tool * feat(context): add raw warehouse discovery tool * feat(context): expose warehouse verification tools to ingest * docs(context): add ingest identifier verification protocol * test(context): guard ingest identifier verification prompts * chore(context): verify warehouse verification tools * docs: add warehouse verification tools plan and spec * fix(context): expose target warehouses to Notion ingest * fix(context): update ingest prompts for warehouse verification tools * fix(context): scope raw schema discovery to allowed connections * fix(context): verify warehouse column display targets * docs: add notion warehouse verification gap closure plan * fix(context): include raw discovery connection names * fix(context): expose warehouse targets for LookML and MetricFlow * fix(context): pass connection config to ingest query executors * fix(cli): enable read-only SQL probes for local ingest * docs: add warehouse verification final v1 closure plan * fix(context): align warehouse sql probe prompt shape * docs: add warehouse verification prompt shape closure plan * test(context): catch connectionless sql execution prompt examples * fix(context): include connection name in sl capture sql example * docs: add warehouse verification sql example closure plan * fix(context): report structured entity detail misses * docs: add warehouse verification structured target miss closure plan * fix: report untracked squash merge conflicts * feat: require ingest verification ledger * fix: stabilize ingest wiki references
49 lines
1.7 KiB
TypeScript
49 lines
1.7 KiB
TypeScript
import type { KtxSqlQueryExecutionInput, KtxSqlQueryExecutorPort } from '@ktx/context/connections';
|
|
import type { KtxLocalProject } from '@ktx/context/project';
|
|
import type { KtxScanConnector, KtxScanContext } from '@ktx/context/scan';
|
|
import { createKtxCliScanConnector } from './local-scan-connectors.js';
|
|
|
|
type CreateConnector = typeof createKtxCliScanConnector;
|
|
|
|
export interface KtxCliIngestQueryExecutorDeps {
|
|
createConnector?: CreateConnector;
|
|
}
|
|
|
|
async function cleanupConnector(connector: KtxScanConnector | null): Promise<void> {
|
|
await connector?.cleanup?.();
|
|
}
|
|
|
|
export function createKtxCliIngestQueryExecutor(
|
|
project: KtxLocalProject,
|
|
deps: KtxCliIngestQueryExecutorDeps = {},
|
|
): KtxSqlQueryExecutorPort {
|
|
const createConnector = deps.createConnector ?? createKtxCliScanConnector;
|
|
return {
|
|
async execute(input: KtxSqlQueryExecutionInput) {
|
|
let connector: KtxScanConnector | null = null;
|
|
try {
|
|
connector = await createConnector(project, input.connectionId);
|
|
if (!connector.capabilities.readOnlySql || !connector.executeReadOnly) {
|
|
throw new Error(
|
|
`Connection "${input.connectionId}" driver "${connector.driver}" does not support read-only SQL execution.`,
|
|
);
|
|
}
|
|
|
|
const ctx: KtxScanContext = { runId: 'ingest-sql-execution' };
|
|
const result = await connector.executeReadOnly(
|
|
{ connectionId: input.connectionId, sql: input.sql, maxRows: input.maxRows },
|
|
ctx,
|
|
);
|
|
return {
|
|
headers: result.headers,
|
|
rows: result.rows,
|
|
totalRows: result.totalRows,
|
|
command: 'SELECT',
|
|
rowCount: result.rowCount,
|
|
};
|
|
} finally {
|
|
await cleanupConnector(connector);
|
|
}
|
|
},
|
|
};
|
|
}
|