mirror of
https://github.com/Kaelio/ktx.git
synced 2026-07-04 10:52:13 +02:00
40 lines
1.3 KiB
TypeScript
40 lines
1.3 KiB
TypeScript
import type { LiveDatabaseIntrospectionPort } from '@ktx/context/ingest';
|
|
import type { KtxProjectConnectionConfig } from '@ktx/context/project';
|
|
import {
|
|
KtxClickHouseScanConnector,
|
|
type KtxClickHouseClientFactory,
|
|
type KtxClickHouseConnectionConfig,
|
|
type KtxClickHouseEndpointResolver,
|
|
} from './connector.js';
|
|
|
|
interface CreateClickHouseLiveDatabaseIntrospectionOptions {
|
|
connections: Record<string, KtxProjectConnectionConfig>;
|
|
clientFactory?: KtxClickHouseClientFactory;
|
|
endpointResolver?: KtxClickHouseEndpointResolver;
|
|
now?: () => Date;
|
|
}
|
|
|
|
export function createClickHouseLiveDatabaseIntrospection(
|
|
options: CreateClickHouseLiveDatabaseIntrospectionOptions,
|
|
): LiveDatabaseIntrospectionPort {
|
|
return {
|
|
async extractSchema(connectionId: string) {
|
|
const connection = options.connections[connectionId] as KtxClickHouseConnectionConfig | undefined;
|
|
const connector = new KtxClickHouseScanConnector({
|
|
connectionId,
|
|
connection,
|
|
clientFactory: options.clientFactory,
|
|
endpointResolver: options.endpointResolver,
|
|
now: options.now,
|
|
});
|
|
try {
|
|
return await connector.introspect(
|
|
{ connectionId, driver: 'clickhouse' },
|
|
{ runId: `clickhouse-${connectionId}` },
|
|
);
|
|
} finally {
|
|
await connector.cleanup();
|
|
}
|
|
},
|
|
};
|
|
}
|