import { type Configuration, type ConnectionOptions } from '../utils/Configuration.js'; import type { LogContext, Logger } from '../logging/Logger.js'; import type { MetadataStorage } from '../metadata/MetadataStorage.js'; import type { ConnectionType, Dictionary, MaybePromise, Primary } from '../typings.js'; import type { Platform } from '../platforms/Platform.js'; import type { TransactionEventBroadcaster } from '../events/TransactionEventBroadcaster.js'; import type { IsolationLevel } from '../enums.js'; /** Abstract base class for database connections, providing transaction and query execution support. */ export declare abstract class Connection { #private; protected readonly config: Configuration; protected readonly type: ConnectionType; protected metadata: MetadataStorage; protected platform: Platform; protected readonly options: ConnectionOptions; protected readonly logger: Logger; protected connected: boolean; constructor(config: Configuration, options?: ConnectionOptions, type?: ConnectionType); /** * Establishes connection to database */ abstract connect(options?: { skipOnConnect?: boolean; }): void | Promise; /** * Are we connected to the database */ abstract isConnected(): Promise; /** * Are we connected to the database */ abstract checkConnection(): Promise<{ ok: true; } | { ok: false; reason: string; error?: Error; }>; /** * Closes the database connection (aka disconnect) */ close(force?: boolean): Promise; /** * Ensure the connection exists, this is used to support lazy connect when using `new MikroORM()` instead of the async `init` method. */ ensureConnection(): Promise; /** * Execute raw SQL queries, handy from running schema dump loaded from a file. * This method doesn't support transactions, as opposed to `orm.schema.execute()`, which is used internally. */ executeDump(dump: string): Promise; protected onConnect(): Promise; /** Executes a callback inside a transaction, committing on success and rolling back on failure. */ transactional(cb: (trx: Transaction) => Promise, options?: { isolationLevel?: IsolationLevel | `${IsolationLevel}`; readOnly?: boolean; ctx?: Transaction; eventBroadcaster?: TransactionEventBroadcaster; loggerContext?: LogContext; }): Promise; /** Begins a new database transaction and returns the transaction context. */ begin(options?: { isolationLevel?: IsolationLevel | `${IsolationLevel}`; readOnly?: boolean; ctx?: Transaction; eventBroadcaster?: TransactionEventBroadcaster; loggerContext?: LogContext; }): Promise; /** Commits the given transaction. */ commit(ctx: Transaction, eventBroadcaster?: TransactionEventBroadcaster, loggerContext?: LogContext): Promise; /** Rolls back the given transaction. */ rollback(ctx: Transaction, eventBroadcaster?: TransactionEventBroadcaster, loggerContext?: LogContext): Promise; /** Executes a raw query and returns the result. */ abstract execute(query: string, params?: any[], method?: 'all' | 'get' | 'run', ctx?: Transaction): Promise | any | any[]>; /** Parses and returns the resolved connection configuration (host, port, user, etc.). */ getConnectionOptions(): ConnectionConfig; /** Sets the metadata storage on this connection. */ setMetadata(metadata: MetadataStorage): void; /** Sets the platform abstraction on this connection. */ setPlatform(platform: Platform): void; /** Returns the platform abstraction for this connection. */ getPlatform(): Platform; protected executeQuery(query: string, cb: () => Promise, context?: LogContext): Promise; protected logQuery(query: string, context?: LogContext): void; } /** Result of a native database query (insert, update, delete). */ export interface QueryResult { affectedRows: number; insertId: Primary; row?: Dictionary; rows?: Dictionary[]; insertedIds?: Primary[]; } /** Resolved database connection parameters. */ export interface ConnectionConfig { host?: string; port?: number; user?: string; password?: string | (() => MaybePromise); database?: string; schema?: string; } /** Opaque transaction context type, wrapping the driver-specific transaction object. */ export type Transaction = T & {};