db: implement asyncDispose

This commit is contained in:
Alex Gleason 2025-02-17 15:15:28 -06:00
parent 951c145138
commit f837083146
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
3 changed files with 6 additions and 1 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,7 @@ export class DittoPostgres {
return pg.connections.idle;
},
listen,
[Symbol.asyncDispose]: () => kysely.destroy(),
};
}
}