Super duper extra close the database

This commit is contained in:
Alex Gleason 2025-02-19 22:00:09 -06:00
parent c6605ece77
commit 6f7fc11635
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
4 changed files with 10 additions and 2 deletions

View file

@ -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;

View file

@ -36,6 +36,10 @@ export class DittoPglite {
poolSize: 1,
availableConnections: 1,
listen,
[Symbol.asyncDispose]: async () => {
await pglite.close();
await kysely.destroy();
},
};
}
}

View file

@ -54,6 +54,10 @@ export class DittoPostgres {
return pg.connections.idle;
},
listen,
[Symbol.asyncDispose]: async () => {
await pg.end();
await kysely.destroy();
},
};
}
}

View file

@ -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]();
},
};
}