@ibm/mapepire-js
Version:
Db2 client for node
126 lines (125 loc) • 4.38 kB
TypeScript
import { SQLJob } from "./sqlJob";
import { BindingValue, DaemonServer, JDBCOptions, QueryOptions } from "./types";
/**
* Represents the options for configuring a connection pool.
*/
export interface PoolOptions {
/** The credentials required to connect to the daemon server. */
creds: DaemonServer;
/**
* Optional JDBC options for configuring the connection.
* These options may include settings such as connection timeout,
* SSL settings, etc.
*/
opts?: JDBCOptions;
/**
* The maximum number of connections allowed in the pool.
* This defines the upper limit on the number of active connections.
*/
maxSize: number;
/**
* The number of connections to create when the pool is initialized.
* This determines the starting size of the connection pool.
*/
startingSize: number;
}
/**
* Represents a connection pool for managing SQL jobs.
*/
export declare class Pool {
private options;
/**
* An array of SQLJob instances managed by the pool.
*/
private jobs;
/**
* Constructs a new Pool instance with the specified options.
*
* @param options - The options for configuring the connection pool.
*/
constructor(options: PoolOptions);
/**
* Initializes the pool by creating a number of SQL jobs defined by the starting size.
*
* @returns A promise that resolves when all jobs have been created.
*/
init(): Promise<SQLJob[]>;
/**
* Checks if there is space available in the pool for more jobs.
*
* @returns True if there is space; otherwise, false.
*/
hasSpace(): boolean;
/**
* Gets the count of active jobs that are either busy or ready.
*
* @returns The number of active jobs.
*/
getActiveJobCount(): number;
/**
* Cleans up the pool by removing jobs that are in invalid states.
*/
cleanup(): void;
/**
* Adds a new job to the pool or reuses an existing job if specified.
*
* @param options - Optional parameters for adding a job.
* @returns A promise that resolves to the added or existing SQL job.
*/
private addJob;
/**
* Retrieves a ready job from the pool.
*
* @returns The first ready job found, or undefined if none are ready.
*/
private getReadyJob;
/**
* Retrieves the index of a ready job in the pool.
*
* @returns The index of the first ready job, or -1 if none are ready.
*/
private getReadyJobIndex;
/**
* Returns a job as fast as possible. It will either be a ready job
* or the job with the least requests on the queue. Will spawn new jobs
* if the pool is not full but all jobs are busy.
* @returns The retrieved job.
*/
getJob(): SQLJob;
/**
* Waits for a job to become available. It will return a ready job if one exists,
* otherwise, it may create a new job if the pool is not full.
*
* @param useNewJob - If true, a new job will be created even if the pool is full.
* @returns A promise that resolves to a ready job.
*/
waitForJob(useNewJob?: boolean): Promise<SQLJob>;
/**
* Pops a job from the pool if one is ready. If no jobs are ready, it will
* create a new job and return that. The returned job should be added back to the pool.
*
* @returns A promise that resolves to a ready job or a new job.
*/
popJob(): Promise<SQLJob>;
/**
* Executes an SQL query using a job from the pool.
*
* @param sql - The SQL query to execute.
* @param opts - Optional settings for the query.
* @returns A promise that resolves to the result of the query execution.
*/
query(sql: string, opts?: QueryOptions): import("./query").Query<unknown>;
/**
* Executes a SQL command using a job from the pool.
*
* @param sql - The SQL command to execute.
* @param opts - Optional settings for the command.
* @returns A promise that resolves to the result of the command execution.
*/
execute<T>(sql: string, opts?: QueryOptions): Promise<import("./types").QueryResult<T>>;
sql<T>(statementParts: TemplateStringsArray, ...parameters: BindingValue[]): Promise<import("./types").QueryResult<T>>;
/**
* Closes all jobs in the pool and releases resources.
*/
end(): void;
}