mirror of
https://github.com/Kaelio/ktx.git
synced 2026-06-10 08:05:14 +02:00
37 lines
1.3 KiB
TypeScript
37 lines
1.3 KiB
TypeScript
import type { LiveDatabaseIntrospectionPort } from '@ktx/context/ingest';
|
|
import type { KtxProjectConnectionConfig } from '@ktx/context/project';
|
|
import {
|
|
KtxPostgresScanConnector,
|
|
type KtxPostgresConnectionConfig,
|
|
type KtxPostgresEndpointResolver,
|
|
type KtxPostgresPoolFactory,
|
|
} from './connector.js';
|
|
|
|
interface CreatePostgresLiveDatabaseIntrospectionOptions {
|
|
connections: Record<string, KtxProjectConnectionConfig>;
|
|
poolFactory?: KtxPostgresPoolFactory;
|
|
endpointResolver?: KtxPostgresEndpointResolver;
|
|
now?: () => Date;
|
|
}
|
|
|
|
export function createPostgresLiveDatabaseIntrospection(
|
|
options: CreatePostgresLiveDatabaseIntrospectionOptions,
|
|
): LiveDatabaseIntrospectionPort {
|
|
return {
|
|
async extractSchema(connectionId: string) {
|
|
const connection = options.connections[connectionId] as KtxPostgresConnectionConfig | undefined;
|
|
const connector = new KtxPostgresScanConnector({
|
|
connectionId,
|
|
connection,
|
|
poolFactory: options.poolFactory,
|
|
endpointResolver: options.endpointResolver,
|
|
now: options.now,
|
|
});
|
|
try {
|
|
return await connector.introspect({ connectionId, driver: 'postgres' }, { runId: `postgres-${connectionId}` });
|
|
} finally {
|
|
await connector.cleanup();
|
|
}
|
|
},
|
|
};
|
|
}
|