mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-15 20:17:22 +00:00
34 lines
1.0 KiB
TypeScript
34 lines
1.0 KiB
TypeScript
import { Kysely, PostgresDialect, type PostgresDialectConfig as KyselyPostgresDialectConfig } from "kysely";
|
|
import { PostgresIntrospector } from "./PostgresIntrospector";
|
|
import { PostgresConnection, plugins } from "./PostgresConnection";
|
|
import { customIntrospector } from "../Connection";
|
|
import type { Pool } from "pg";
|
|
|
|
export type PostgresDialectConfig = Omit<KyselyPostgresDialectConfig, "pool"> & {
|
|
pool: Pool;
|
|
};
|
|
|
|
export class PgPostgresConnection extends PostgresConnection<Pool> {
|
|
override name = "pg";
|
|
|
|
constructor(config: PostgresDialectConfig) {
|
|
const kysely = new Kysely({
|
|
dialect: customIntrospector(PostgresDialect, PostgresIntrospector, {
|
|
excludeTables: [],
|
|
}).create(config),
|
|
plugins,
|
|
});
|
|
|
|
super(kysely);
|
|
this.client = config.pool;
|
|
}
|
|
|
|
override async close(): Promise<void> {
|
|
await this.client.end();
|
|
}
|
|
}
|
|
|
|
export function pg(config: PostgresDialectConfig): PgPostgresConnection {
|
|
return new PgPostgresConnection(config);
|
|
}
|