mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
Super duper extra close the database
This commit is contained in:
parent
c6605ece77
commit
6f7fc11635
4 changed files with 10 additions and 2 deletions
|
|
@ -2,7 +2,7 @@ import type { Kysely } from 'kysely';
|
|||
|
||||
import type { DittoTables } from './DittoTables.ts';
|
||||
|
||||
export interface DittoDatabase {
|
||||
export interface DittoDatabase extends AsyncDisposable {
|
||||
readonly kysely: Kysely<DittoTables>;
|
||||
readonly poolSize: number;
|
||||
readonly availableConnections: number;
|
||||
|
|
|
|||
|
|
@ -36,6 +36,10 @@ export class DittoPglite {
|
|||
poolSize: 1,
|
||||
availableConnections: 1,
|
||||
listen,
|
||||
[Symbol.asyncDispose]: async () => {
|
||||
await pglite.close();
|
||||
await kysely.destroy();
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,6 +54,10 @@ export class DittoPostgres {
|
|||
return pg.connections.idle;
|
||||
},
|
||||
listen,
|
||||
[Symbol.asyncDispose]: async () => {
|
||||
await pg.end();
|
||||
await kysely.destroy();
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ export async function createTestDB(opts?: { pure?: boolean }) {
|
|||
await sql`truncate table ${sql.ref(tablename)} cascade`.execute(db.kysely);
|
||||
}
|
||||
|
||||
await db.kysely.destroy();
|
||||
await db[Symbol.asyncDispose]();
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue