mirror of
https://github.com/aljazceru/ditto.git
synced 2026-01-23 07:14:22 +01:00
replace kysely_deno_postgres with kysely-postgres-js
This commit is contained in:
@@ -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
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user