mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
Add PGLITE_DEBUG environment variable
This commit is contained in:
parent
4d0ae401b3
commit
8e3ddaa056
5 changed files with 16 additions and 5 deletions
|
|
@ -77,6 +77,10 @@ class Conf {
|
||||||
static get testDatabaseUrl(): string {
|
static get testDatabaseUrl(): string {
|
||||||
return Deno.env.get('TEST_DATABASE_URL') ?? 'memory://';
|
return Deno.env.get('TEST_DATABASE_URL') ?? 'memory://';
|
||||||
}
|
}
|
||||||
|
/** PGlite debug level. 0 disables logging. */
|
||||||
|
static get pgliteDebug(): 0 | 1 | 2 | 3 | 4 | 5 {
|
||||||
|
return Number(Deno.env.get('PGLITE_DEBUG') || 0) as 0 | 1 | 2 | 3 | 4 | 5;
|
||||||
|
}
|
||||||
static db = {
|
static db = {
|
||||||
/** Database query timeout configurations. */
|
/** Database query timeout configurations. */
|
||||||
timeouts: {
|
timeouts: {
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ export class DittoDB {
|
||||||
switch (protocol) {
|
switch (protocol) {
|
||||||
case 'file:':
|
case 'file:':
|
||||||
case 'memory:':
|
case 'memory:':
|
||||||
return DittoPglite.create(databaseUrl);
|
return DittoPglite.create(databaseUrl, opts);
|
||||||
case 'postgres:':
|
case 'postgres:':
|
||||||
case 'postgresql:':
|
case 'postgresql:':
|
||||||
return DittoPostgres.create(databaseUrl, opts);
|
return DittoPostgres.create(databaseUrl, opts);
|
||||||
|
|
|
||||||
|
|
@ -10,4 +10,5 @@ export interface DittoDatabase {
|
||||||
|
|
||||||
export interface DittoDatabaseOpts {
|
export interface DittoDatabaseOpts {
|
||||||
poolSize?: number;
|
poolSize?: number;
|
||||||
|
debug?: 0 | 1 | 2 | 3 | 4 | 5;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,15 +3,18 @@ import { pg_trgm } from '@electric-sql/pglite/contrib/pg_trgm';
|
||||||
import { PgliteDialect } from '@soapbox/kysely-pglite';
|
import { PgliteDialect } from '@soapbox/kysely-pglite';
|
||||||
import { Kysely } from 'kysely';
|
import { Kysely } from 'kysely';
|
||||||
|
|
||||||
import { DittoDatabase } from '@/db/DittoDatabase.ts';
|
import { DittoDatabase, DittoDatabaseOpts } from '@/db/DittoDatabase.ts';
|
||||||
import { DittoTables } from '@/db/DittoTables.ts';
|
import { DittoTables } from '@/db/DittoTables.ts';
|
||||||
import { KyselyLogger } from '@/db/KyselyLogger.ts';
|
import { KyselyLogger } from '@/db/KyselyLogger.ts';
|
||||||
|
|
||||||
export class DittoPglite {
|
export class DittoPglite {
|
||||||
static create(databaseUrl: string): DittoDatabase {
|
static create(databaseUrl: string, opts?: DittoDatabaseOpts): DittoDatabase {
|
||||||
const kysely = new Kysely<DittoTables>({
|
const kysely = new Kysely<DittoTables>({
|
||||||
dialect: new PgliteDialect({
|
dialect: new PgliteDialect({
|
||||||
database: new PGlite(databaseUrl, { extensions: { pg_trgm } }),
|
database: new PGlite(databaseUrl, {
|
||||||
|
extensions: { pg_trgm },
|
||||||
|
debug: opts?.debug,
|
||||||
|
}),
|
||||||
}),
|
}),
|
||||||
log: KyselyLogger,
|
log: KyselyLogger,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,10 @@ export class Storages {
|
||||||
public static async database(): Promise<DittoDatabase> {
|
public static async database(): Promise<DittoDatabase> {
|
||||||
if (!this._database) {
|
if (!this._database) {
|
||||||
this._database = (async () => {
|
this._database = (async () => {
|
||||||
const db = DittoDB.create(Conf.databaseUrl, { poolSize: Conf.pg.poolSize });
|
const db = DittoDB.create(Conf.databaseUrl, {
|
||||||
|
poolSize: Conf.pg.poolSize,
|
||||||
|
debug: Conf.pgliteDebug,
|
||||||
|
});
|
||||||
await DittoDB.migrate(db.kysely);
|
await DittoDB.migrate(db.kysely);
|
||||||
return db;
|
return db;
|
||||||
})();
|
})();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue