From c2f578a2bbd1b00dd37c739d71dc58d95aba695c Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 16 Jul 2024 09:26:49 -0500 Subject: [PATCH] DittoPostgres: handle pool not being opened yet --- src/db/adapters/DittoPostgres.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/db/adapters/DittoPostgres.ts b/src/db/adapters/DittoPostgres.ts index bcd4ff20..3be08d47 100644 --- a/src/db/adapters/DittoPostgres.ts +++ b/src/db/adapters/DittoPostgres.ts @@ -1,5 +1,5 @@ import { Kysely } from 'kysely'; -import { PostgresJSDialect } from 'kysely-postgres-js'; +import { PostgresJSDialect, PostgresJSDialectConfig } from 'kysely-postgres-js'; import postgres from 'postgres'; import { Conf } from '@/config.ts'; @@ -8,7 +8,7 @@ import { KyselyLogger } from '@/db/KyselyLogger.ts'; export class DittoPostgres { static db: Kysely | undefined; - static postgres: postgres.Sql; + static postgres?: postgres.Sql; // deno-lint-ignore require-await static async getInstance(): Promise> { @@ -19,8 +19,7 @@ export class DittoPostgres { if (!this.db) { this.db = new Kysely({ dialect: new PostgresJSDialect({ - // @ts-ignore: mismatched library versions - postgres: this.postgres, + postgres: this.postgres as unknown as PostgresJSDialectConfig['postgres'], }), log: KyselyLogger, }); @@ -30,10 +29,10 @@ export class DittoPostgres { } static get poolSize() { - return Conf.pg.poolSize; + return this.postgres?.connections.open ?? 0; } static get availableConnections(): number { - return this.postgres.connections.idle; + return this.postgres?.connections.idle ?? 0; } }