Skip to content

Commit

Permalink
make pool max connections and compression configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
pj-spoelders committed Oct 10, 2024
1 parent af15360 commit 70ac507
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions src/lib/sql-client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as forge from 'node-forge';


import { getURIScheme } from './utils';
import { CreatePreparedStatementResponse, PublicKeyResponse, SQLQueriesResponse, SQLResponse } from './types';
import { Statement } from './statement';
Expand Down Expand Up @@ -44,6 +43,7 @@ export interface Config {
interface InternalConfig {
apiVersion: number;
compression: boolean;
poolMaxConnections: number;
}

export const driverVersion = 'v1.0.0';
Expand All @@ -61,16 +61,21 @@ export class ExasolDriver implements IExasolDriver {
encryption: true,
compression: false,
apiVersion: 3,
poolMaxConnections: 1,
};
private readonly config: Config & InternalConfig & { websocketFactory: websocketFactory };
private readonly logger: ILogger;
private closed = false;

private readonly pool: ConnectionPool<Connection>;

constructor(websocketFactory: websocketFactory, config: Partial<Config>, logger: ILogger = new Logger(LogLevel.Debug)) {
constructor(
websocketFactory: websocketFactory,
config: Partial<Config> & Partial<InternalConfig>,
logger: ILogger = new Logger(LogLevel.Debug),
) {
// Used internally to avoid parallel execution
this.pool = new ConnectionPool<Connection>(1, logger);
this.pool = new ConnectionPool<Connection>(config.poolMaxConnections, logger);
this.config = {
...this.defaultConfig,
...config,
Expand Down Expand Up @@ -207,25 +212,25 @@ export class ExasolDriver implements IExasolDriver {
async query(
sqlStatement: string,
attributes?: Partial<Attributes> | undefined,
getCancel?: CetCancelFunction | undefined
getCancel?: CetCancelFunction | undefined,
): Promise<QueryResult>;
async query(
sqlStatement: string,
attributes?: Partial<Attributes> | undefined,
getCancel?: CetCancelFunction | undefined,
responseType?: 'default' | undefined
responseType?: 'default' | undefined,
): Promise<QueryResult>;
async query(
sqlStatement: string,
attributes?: Partial<Attributes> | undefined,
getCancel?: CetCancelFunction | undefined,
responseType?: 'raw' | undefined
responseType?: 'raw' | undefined,
): Promise<SQLResponse<SQLQueriesResponse>>;
async query(
sqlStatement: string,
attributes?: Partial<Attributes> | undefined,
getCancel?: CetCancelFunction | undefined,
responseType?: 'default' | 'raw'
responseType?: 'default' | 'raw',
): Promise<QueryResult | SQLResponse<SQLQueriesResponse>> {
const connection = await this.acquire();
return connection
Expand Down Expand Up @@ -268,25 +273,25 @@ export class ExasolDriver implements IExasolDriver {
async execute(
sqlStatement: string,
attributes?: Partial<Attributes> | undefined,
getCancel?: CetCancelFunction | undefined
getCancel?: CetCancelFunction | undefined,
): Promise<number>;
async execute(
sqlStatement: string,
attributes?: Partial<Attributes> | undefined,
getCancel?: CetCancelFunction | undefined,
responseType?: 'default' | undefined
responseType?: 'default' | undefined,
): Promise<number>;
async execute(
sqlStatement: string,
attributes?: Partial<Attributes> | undefined,
getCancel?: CetCancelFunction | undefined,
responseType?: 'raw' | undefined
responseType?: 'raw' | undefined,
): Promise<SQLResponse<SQLQueriesResponse>>;
async execute(
sqlStatement: string,
attributes?: Partial<Attributes> | undefined,
getCancel?: CetCancelFunction | undefined,
responseType?: 'default' | 'raw'
responseType?: 'default' | 'raw',
): Promise<SQLResponse<SQLQueriesResponse> | number> {
const connection = await this.acquire();
return connection
Expand Down Expand Up @@ -329,7 +334,7 @@ export class ExasolDriver implements IExasolDriver {
public async executeBatch(
sqlStatements: string[],
attributes?: Partial<Attributes>,
getCancel?: CetCancelFunction
getCancel?: CetCancelFunction,
): Promise<SQLResponse<SQLQueriesResponse>> {
const connection = await this.acquire();

Expand Down Expand Up @@ -363,7 +368,7 @@ export class ExasolDriver implements IExasolDriver {
command: 'createPreparedStatement',
sqlText: sqlStatement,
},
getCancel
getCancel,
)
.then((response) => {
return new Statement(connection, this.pool, response.responseData.statementHandle, response.responseData.parameterData.columns);
Expand Down Expand Up @@ -408,13 +413,12 @@ export class ExasolDriver implements IExasolDriver {
}
return connection;
}

private async loginBasicAuth() {
return this.sendCommand<PublicKeyResponse>({
command: 'login',
protocolVersion: this.config.apiVersion,
}).then((response) => {

const n = new forge.jsbn.BigInteger(response.responseData.publicKeyModulus, 16);
const e = new forge.jsbn.BigInteger(response.responseData.publicKeyExponent, 16);

Expand Down

0 comments on commit 70ac507

Please sign in to comment.