@hotmeshio/hotmesh
Version:
Permanent-Memory Workflows & AI Agents
68 lines (67 loc) • 3.03 kB
TypeScript
import { AbstractConnection } from '..';
import { PostgresClientOptions, PostgresClientType, PostgresClassType, PostgresPoolClientType } from '../../../types/postgres';
declare class PostgresConnection extends AbstractConnection<PostgresClassType, PostgresClientOptions> {
defaultOptions: PostgresClientOptions;
protected static poolClientInstances: Set<PostgresPoolClientType>;
protected static connectionInstances: Set<PostgresClientType>;
protected static taskQueueConnections: Map<string, PostgresConnection>;
/**
* Get comprehensive connection statistics for monitoring taskQueue pooling effectiveness
*/
static getConnectionStats(): {
totalPoolClients: number;
totalConnections: number;
taskQueueConnections: number;
taskQueueDetails: Array<{
key: string;
connectionId: string;
reusedCount: number;
}>;
};
/**
* Log current connection statistics - useful for debugging connection pooling
*/
static logConnectionStats(logger?: any): void;
/**
* Check taskQueue pooling effectiveness - returns metrics about connection reuse
*/
static getPoolingEffectiveness(): {
totalConnections: number;
taskQueuePools: number;
totalReuses: number;
averageReusesPerPool: number;
poolingEfficiency: number;
};
poolClientInstance: PostgresPoolClientType;
createConnection(clientConstructor: any, options: PostgresClientOptions, config?: {
connect?: boolean;
provider?: string;
}): Promise<PostgresClientType>;
getClient(): PostgresClientType;
/**
* Get the connection ID for monitoring purposes
*/
getConnectionId(): string | null;
static disconnectAll(): Promise<void>;
static disconnectPoolClients(): Promise<void>;
static disconnectConnections(): Promise<void>;
closeConnection(connection: PostgresClientType): Promise<void>;
static isPoolClient(client: any): client is PostgresPoolClientType;
/**
* Creates a taskQueue-based connection key for connection pooling.
* This allows multiple providers (store, sub, stream) to reuse the same connection
* when they share the same taskQueue and database configuration.
*/
private static createTaskQueueConnectionKey;
/**
* Gets or creates a PostgreSQL connection based on taskQueue and database configuration.
* If a connection already exists for the same taskQueue + config, it will be reused.
* This optimization reduces connection overhead for PostgreSQL providers.
*/
static getOrCreateTaskQueueConnection(id: string, taskQueue: string | undefined, clientConstructor: PostgresClassType, options: PostgresClientOptions, config?: {
connect?: boolean;
provider?: string;
}): Promise<PostgresConnection>;
static getTransactionClient(transactionClient: any): Promise<['client' | 'poolclient', PostgresClientType]>;
}
export { PostgresConnection };