diff --git a/src/lib/pool/pool.ts b/src/lib/pool/pool.ts index 336d390..d4b5a6e 100644 --- a/src/lib/pool/pool.ts +++ b/src/lib/pool/pool.ts @@ -6,10 +6,16 @@ export interface PoolItem { active?: boolean; name: string; } - +//TODO: multiple todos here, +//TBD: how do we want the pool to be filled? on request, on driver startup? +//TBD: a min pool size? +//TBD: a query time out parameter to 'unblock' the pool? also check connection for this export class ConnectionPool { private readonly pool = new Map(); - constructor(private readonly max = 1, private readonly logger: ILogger) {} + constructor( + private readonly max = 1, + private readonly logger: ILogger, + ) {} async add(connection: T): Promise { this.logger.debug(`[Pool:${connection.name}] Add connection`); @@ -46,6 +52,7 @@ export class ConnectionPool { acquire(): T | undefined { const keys = Array.from(this.pool.keys()); + for (let index = 0; index < keys.length; index++) { const key = keys[index]; const item = this.pool.get(key); diff --git a/src/lib/sql-client.ts b/src/lib/sql-client.ts index 440eb80..98c8a7c 100644 --- a/src/lib/sql-client.ts +++ b/src/lib/sql-client.ts @@ -92,6 +92,9 @@ export class ExasolDriver implements IExasolDriver { //solution would be to hollow out this function, maybe have it call acquire() instead and have acquire call a new function containing this logic //a la "create connection and add to pool public async connect(): Promise { + await this.acquire(); + } + private async createConnectionAndAddToPool(): Promise { let hasCredentials = false; let isBasicAuth = false; if (this.config.user && this.config.password) { @@ -423,7 +426,7 @@ export class ExasolDriver implements IExasolDriver { } else { //create a new connection if the pool is not at max size, add it to the pool and then acquire it. this.logger.debug('[SQLClient] Found no free connection and pool did not reach its limit, will create new connection'); - await this.connect(); // connect will create a connection and add it to the pool + await this.createConnectionAndAddToPool(); connection = this.pool.acquire(); } if (!connection) {