mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-17 21:06:04 +00:00
Aligned connection constructors to include an explicit name parameter, updated documentation, and streamlined connection methods for consistency. Adjusted dependencies and cleaned unused references.
44 lines
1.4 KiB
TypeScript
44 lines
1.4 KiB
TypeScript
import { Kysely } from "kysely";
|
|
import { PostgresIntrospector } from "./PostgresIntrospector";
|
|
import { PostgresConnection, plugins } from "./PostgresConnection";
|
|
import { customIntrospector } from "bknd";
|
|
import { PostgresJSDialect } from "kysely-postgres-js";
|
|
import $postgresJs, { type Sql, type Options, type PostgresType } from "postgres";
|
|
|
|
export type PostgresJsConfig = Options<Record<string, PostgresType>>;
|
|
|
|
export class PostgresJsConnection extends PostgresConnection {
|
|
override name = "postgres-js";
|
|
|
|
private postgres: Sql;
|
|
|
|
constructor(opts: { postgres: Sql }) {
|
|
const kysely = new Kysely({
|
|
dialect: customIntrospector(PostgresJSDialect, PostgresIntrospector, {
|
|
excludeTables: [],
|
|
}).create({ postgres: opts.postgres }),
|
|
plugins,
|
|
});
|
|
|
|
super(kysely);
|
|
this.postgres = opts.postgres;
|
|
}
|
|
|
|
override async close(): Promise<void> {
|
|
await this.postgres.end();
|
|
}
|
|
}
|
|
|
|
export function postgresJs(
|
|
connectionString: string,
|
|
config?: PostgresJsConfig,
|
|
): PostgresJsConnection;
|
|
export function postgresJs(config: PostgresJsConfig): PostgresJsConnection;
|
|
export function postgresJs(
|
|
first: PostgresJsConfig | string,
|
|
second?: PostgresJsConfig,
|
|
): PostgresJsConnection {
|
|
const postgres = typeof first === "string" ? $postgresJs(first, second) : $postgresJs(first);
|
|
return new PostgresJsConnection({ postgres });
|
|
}
|