Skip to content

Commit f8587a2

Browse files
committed
feat: add _clients
1 parent a9c6f0e commit f8587a2

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/bridge.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,18 @@ type QueryResult = {
3838
rows: Row[],
3939
};
4040

41+
type Client = AnySql & {events: EventEmitter, };
42+
4143
export const createBridge = (postgres: typeof Postgres) => {
4244
return class PostgresBridge {
4345
private readonly poolEvents: EventEmitter;
4446

45-
private readonly pool: GenericPool<AnySql & {events: EventEmitter, }>;
47+
private readonly pool: GenericPool<Client>;
4648

4749
public constructor (poolConfiguration: PgPool) {
4850
this.poolEvents = new EventEmitter();
4951

50-
this.pool = genericPool.createPool<AnySql & {events: EventEmitter, }>({
52+
this.pool = genericPool.createPool<Client>({
5153
create: async () => {
5254
const connectionEvents = new EventEmitter();
5355

@@ -71,7 +73,7 @@ export const createBridge = (postgres: typeof Postgres) => {
7173
port: poolConfiguration.port ?? 5_432,
7274
ssl: poolConfiguration.ssl,
7375
username: poolConfiguration.user,
74-
}) as AnySql & {events: EventEmitter, };
76+
}) as Client;
7577

7678
connection.events = connectionEvents;
7779

@@ -131,6 +133,11 @@ export const createBridge = (postgres: typeof Postgres) => {
131133
await client.end();
132134
}
133135

136+
public _clients () {
137+
// @ts-expect-error accessing private method
138+
return Array.from(this.pool._allObjects);
139+
}
140+
134141
public get idleCount () {
135142
return this.pool.available;
136143
}

0 commit comments

Comments
 (0)