UNPKG

@voicenter-team/mysql-dynamic-cluster

Version:

Galera cluster with implementation of dynamic choose mysql server for queries, caching, hashing it and metrics

85 lines (84 loc) 2.44 kB
/** * Created by Bohdan on Sep, 2021 */ import { IQueryOptions, QueryValues, ClusterEvent, QueryResult } from '../types/PoolInterfaces'; import { Pool } from "../pool/Pool"; export declare class GaleraCluster { connected: boolean; private readonly _pools; /** * Get all pools * @internal */ get pools(): Pool[]; private readonly _useClusterHashing; private readonly _clusterHashing; private readonly _serviceNames; private readonly _errorRetryCount; private readonly _useRedis; private readonly _clusterName; private readonly _nullServiceName; /** * @param userSettings global user settings */ constructor(); /** * Sort pool ids for mix userSettings and autogenerated ids * @param pools pools passed in userSettings * @private */ private _sortPoolIds; /** * Connect all cluster pools what created from host information in config */ connect(): Promise<void>; /** * Enable hashing for cluster */ private _enableHashing; /** * Disconnect all cluster pools */ disconnect(): Promise<void>; /** * Connect to the event * @param event event name * @param callback function what will be called after emit */ on(event: ClusterEvent, callback: (...args: any[]) => void): void; /** * Cluster mysql query * @param sql MySQL query * @param values values what passed in sql string * @param queryOptions params for configure query */ query<T extends QueryResult>(sql: string, values?: QueryValues, queryOptions?: IQueryOptions): Promise<T>; /** * Query request to pool * @param sql MySQL query string * @param pool active pool * @param queryOptions options to configure query * @private */ private _queryRequest; /** * Count max retry after error * @param maxRetry max retry count after error * @param activePoolsLength length active pools what passed the validator * @private */ private _maxRetryCount; /** * Mix together values and sql string * @param sql MySQL query * @param values values to mix with sql * @private */ private _formatSQL; /** * Get all active pools what passed the validator * @param serviceId serviceId of what need to hashing in the cluster * @private */ private _getActivePools; }