import { Readable } from 'stream'; import { IDatabaseConnection } from './IDatabaseConnection'; import { IQueryable } from './IQueryable'; import { IsolationLevel } from './IsolationLevel'; import { IDatabasePosition } from './IDatabasePosition'; export declare const LINGER_WARNING: number; export declare const DEFAULT_QUERY_TIMEOUT: number; export declare const RECURRING_WARNING_TIMER: number; /** * Do not call `new Database` directly. Use `Database.getConnection` to create a `DatabaseConnection` object. * @abstract * @implements `IDatabaseConnection` * @class */ export declare abstract class DatabaseConnection implements IDatabaseConnection { private $api; private $readOnly; private $timeout; private $lingerTimer; private $lingerInterval; private $lingerTickCount; private $instantiationStack; private $open; constructor(api: TAPI, isReadOnly: boolean, instantiationStack: string); abstract isMaster(): boolean; abstract isReplication(): boolean; abstract hasReplicationEnabled(): boolean; private $triggerLingerWarning; setInstantiationStack(stack: string): void; /** * Gets the callback stacktrace to determine what opened * this connection. Useful for debugging lingering connections. * @returns string - A stacktrace */ getInstantiationStack(): string; private $disarmLingerWarnings; private $armLingerWarning; /** * Gets the underlying Database API * @returns any */ getAPI(): TAPI; abstract formatQuery(query: IQueryable, params?: any): string; /** * Returns true if connection was created without * write access * @returns boolean */ isReadOnly(): boolean; /** * Sets the timeout of this connectino * * @param timeout in milliseconds */ setTimeout(timeout: number): void; /** * Returns the current timeout setting * @returns number in milliseconds */ getTimeout(): number; /** * Queries the database for a dataset. * * @param {Query} query The database query * @async * @returns Promise */ query(query: IQueryable): Promise; /** * * @param query The database query * @param params Parameters for the query * @param streamOptions Stream options * @returns Readable */ stream(query: IQueryable, streamOptions?: any): Readable; /** * Closes the connection. May error if connection has an active transaction. * if `forceClose` boolean is true, it will force close the connection, regardless * of transaction state. * * @param forceClose optional boolean * @async * @returns Promise */ close(forceClose?: boolean): Promise; /** * Returns true if the connection has been closed. */ isClosed(): boolean; /** * Implementation method to start a transaction. * * @abstract * @async * @returns Promise */ abstract startTransaction(isolationLevel?: IsolationLevel): Promise; /** * Implementation method to determine if the connection is in an active transaction. * * @abstract * @returns boolean */ abstract isTransaction(): boolean; /** * Ends a transaction. if `requiresRollback` is `true`, then `rollback()` is invoked. Otherwise, `commit()` is invoked. * * @abstract * @async * @param requiresRollback optional boolean * @returns Promise */ abstract endTransaction(requiresRollback?: boolean): Promise; /** * Commits a transaction. This will end a transaction. * * @abstract * @async * @returns Promise */ abstract commit(): Promise; /** * Rollsback a transaction. This will end a transaction. * * @abstract * @async * @returns Promise */ abstract rollback(): Promise; /** * Implementation to close the connection, if `forceClose` is true, close the connection no matter what. * Silently error if it means the connection is closed. * * @param forceClose boolean, if `true`, should close the connection no matter what. * @async * @returns Promise */ protected abstract _close(forceClose: boolean): Promise; /** * Implementation method to return a dataset from the database * * @param query The database query * @param params The query parameters * @async * @returns Promise */ protected abstract _query(query: string, params?: any): Promise; /** * Implementation method to return a dataset from the database like `query()`, * but returns a `Readable` stream instead. * * @param query The database query * @param params The query parameters * @param streamOptions `Readable` stream options * @returns `Readable` */ protected abstract _stream(query: string, params?: any, streamOptions?: any): Readable; /** * @since 8.1.0 */ abstract getCurrentDatabasePosition(): Promise; }