ktx/packages/connector-postgres/src/historic-sql-query-client.ts

38 lines
1.1 KiB
TypeScript
Raw Normal View History

2026-05-10 23:51:24 +02:00
import type { KtxPostgresQueryClient } from '@ktx/context/ingest';
import { KtxPostgresScanConnector, type KtxPostgresScanConnectorOptions } from './connector.js';
2026-05-10 23:12:26 +02:00
2026-05-10 23:51:24 +02:00
export type KtxPostgresHistoricSqlQueryClientOptions = KtxPostgresScanConnectorOptions;
2026-05-10 23:12:26 +02:00
2026-05-10 23:51:24 +02:00
export class KtxPostgresHistoricSqlQueryClient implements KtxPostgresQueryClient {
2026-05-10 23:12:26 +02:00
private readonly connectionId: string;
2026-05-10 23:51:24 +02:00
private readonly connector: KtxPostgresScanConnector;
2026-05-10 23:12:26 +02:00
2026-05-10 23:51:24 +02:00
constructor(options: KtxPostgresHistoricSqlQueryClientOptions) {
2026-05-10 23:12:26 +02:00
this.connectionId = options.connectionId;
2026-05-10 23:51:24 +02:00
this.connector = new KtxPostgresScanConnector(options);
2026-05-10 23:12:26 +02:00
}
async executeQuery(
sql: string,
params?: unknown[],
): Promise<{ headers: string[]; rows: unknown[][]; totalRows: number }> {
const result = await this.connector.executeReadOnly(
{
connectionId: this.connectionId,
sql,
params,
},
{} as never,
);
return {
headers: result.headers,
rows: result.rows,
totalRows: result.totalRows,
};
}
async cleanup(): Promise<void> {
await this.connector.cleanup();
}
}