mirror of
https://github.com/Kaelio/ktx.git
synced 2026-06-10 08:05:14 +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 {
|
|
KtxSqlServerScanConnector,
|
|
type KtxSqlServerConnectionConfig,
|
|
type KtxSqlServerEndpointResolver,
|
|
type KtxSqlServerPoolFactory,
|
|
} from './connector.js';
|
|
|
|
interface CreateSqlServerLiveDatabaseIntrospectionOptions {
|
|
connections: Record<string, KtxProjectConnectionConfig>;
|
|
poolFactory?: KtxSqlServerPoolFactory;
|
|
endpointResolver?: KtxSqlServerEndpointResolver;
|
|
now?: () => Date;
|
|
}
|
|
|
|
export function createSqlServerLiveDatabaseIntrospection(
|
|
options: CreateSqlServerLiveDatabaseIntrospectionOptions,
|
|
): LiveDatabaseIntrospectionPort {
|
|
return {
|
|
async extractSchema(connectionId: string) {
|
|
const connection = options.connections[connectionId] as KtxSqlServerConnectionConfig | undefined;
|
|
const connector = new KtxSqlServerScanConnector({
|
|
connectionId,
|
|
connection,
|
|
poolFactory: options.poolFactory,
|
|
endpointResolver: options.endpointResolver,
|
|
now: options.now,
|
|
});
|
|
try {
|
|
return await connector.introspect(
|
|
{ connectionId, driver: 'sqlserver' },
|
|
{ runId: `sqlserver-${connectionId}` },
|
|
);
|
|
} finally {
|
|
await connector.cleanup();
|
|
}
|
|
},
|
|
};
|
|
}
|