replace kysely_deno_postgres with kysely-postgres-js

This commit is contained in:
Siddharth Singh
2024-06-30 13:13:01 +05:30
parent bdd3b2224e
commit ae140933f5
3 changed files with 24 additions and 28 deletions

View File

@@ -1,6 +1,6 @@
import { Kysely, PostgresAdapter, PostgresIntrospector, PostgresQueryCompiler } from 'kysely';
import { PostgreSQLDriver } from 'kysely_deno_postgres';
import { Pool } from 'postgres';
import { Kysely } from 'kysely';
import { PostgresJSDialect } from "kysely-postgres-js";
import postgres from 'postgres';
import { Conf } from '@/config.ts';
import { DittoTables } from '@/db/DittoTables.ts';
@@ -8,34 +8,15 @@ import { KyselyLogger } from '@/db/KyselyLogger.ts';
export class DittoPostgres {
static db: Kysely<DittoTables> | undefined;
static pool: Pool | undefined;
static getPool(): Pool {
if (!this.pool) {
this.pool = new Pool(Conf.databaseUrl, Conf.pg.poolSize);
}
return this.pool;
}
// deno-lint-ignore require-await
static async getInstance(): Promise<Kysely<DittoTables>> {
if (!this.db) {
this.db = new Kysely({
dialect: {
createAdapter() {
return new PostgresAdapter();
},
createDriver() {
return new PostgreSQLDriver(DittoPostgres.getPool());
},
createIntrospector(db: Kysely<unknown>) {
return new PostgresIntrospector(db);
},
createQueryCompiler() {
return new PostgresQueryCompiler();
},
},
log: KyselyLogger,
dialect: new PostgresJSDialect({
postgres: postgres(Conf.databaseUrl)
}),
log: KyselyLogger
});
}