mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
DittoPostgres: handle pool not being opened yet
This commit is contained in:
parent
e208d7ef56
commit
c2f578a2bb
1 changed files with 5 additions and 6 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
import { Kysely } from 'kysely';
|
import { Kysely } from 'kysely';
|
||||||
import { PostgresJSDialect } from 'kysely-postgres-js';
|
import { PostgresJSDialect, PostgresJSDialectConfig } from 'kysely-postgres-js';
|
||||||
import postgres from 'postgres';
|
import postgres from 'postgres';
|
||||||
|
|
||||||
import { Conf } from '@/config.ts';
|
import { Conf } from '@/config.ts';
|
||||||
|
|
@ -8,7 +8,7 @@ import { KyselyLogger } from '@/db/KyselyLogger.ts';
|
||||||
|
|
||||||
export class DittoPostgres {
|
export class DittoPostgres {
|
||||||
static db: Kysely<DittoTables> | undefined;
|
static db: Kysely<DittoTables> | undefined;
|
||||||
static postgres: postgres.Sql;
|
static postgres?: postgres.Sql;
|
||||||
|
|
||||||
// deno-lint-ignore require-await
|
// deno-lint-ignore require-await
|
||||||
static async getInstance(): Promise<Kysely<DittoTables>> {
|
static async getInstance(): Promise<Kysely<DittoTables>> {
|
||||||
|
|
@ -19,8 +19,7 @@ export class DittoPostgres {
|
||||||
if (!this.db) {
|
if (!this.db) {
|
||||||
this.db = new Kysely({
|
this.db = new Kysely({
|
||||||
dialect: new PostgresJSDialect({
|
dialect: new PostgresJSDialect({
|
||||||
// @ts-ignore: mismatched library versions
|
postgres: this.postgres as unknown as PostgresJSDialectConfig['postgres'],
|
||||||
postgres: this.postgres,
|
|
||||||
}),
|
}),
|
||||||
log: KyselyLogger,
|
log: KyselyLogger,
|
||||||
});
|
});
|
||||||
|
|
@ -30,10 +29,10 @@ export class DittoPostgres {
|
||||||
}
|
}
|
||||||
|
|
||||||
static get poolSize() {
|
static get poolSize() {
|
||||||
return Conf.pg.poolSize;
|
return this.postgres?.connections.open ?? 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static get availableConnections(): number {
|
static get availableConnections(): number {
|
||||||
return this.postgres.connections.idle;
|
return this.postgres?.connections.idle ?? 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue