import { type ControlledTransaction, type Dialect, Kysely } from 'kysely';
import {
  type AnyEntity,
  Connection,
  type Dictionary,
  type EntityData,
  type IsolationLevel,
  type LogContext,
  type LoggingOptions,
  type MaybePromise,
  type QueryResult,
  RawQueryFragment,
  type Transaction,
  type TransactionEventBroadcaster,
} from '@mikro-orm/core';
import type { AbstractSqlPlatform } from './AbstractSqlPlatform.js';
import { NativeQueryBuilder } from './query/NativeQueryBuilder.js';
/** Base class for SQL database connections, built on top of Kysely. */
export declare abstract class AbstractSqlConnection extends Connection {
  #private;
  protected platform: AbstractSqlPlatform;
  /** Creates a Kysely dialect instance with driver-specific configuration. */
  abstract createKyselyDialect(overrides: Dictionary): MaybePromise<Dialect>;
  /** Establishes the database connection and runs the onConnect hook. */
  connect(options?: { skipOnConnect?: boolean }): Promise<void>;
  /** Initializes the Kysely client from driver options or a user-provided Kysely instance. */
  createKysely(): MaybePromise<void>;
  /**
   * @inheritDoc
   */
  close(force?: boolean): Promise<void>;
  /**
   * @inheritDoc
   */
  isConnected(): Promise<boolean>;
  /**
   * @inheritDoc
   */
  checkConnection(): Promise<
    | {
        ok: true;
      }
    | {
        ok: false;
        reason: string;
        error?: Error;
      }
  >;
  /** Returns the underlying Kysely client, creating it synchronously if needed. */
  getClient<T = any>(): Kysely<T>;
  /** Ensures the Kysely client is initialized, creating it asynchronously if needed. */
  initClient(): Promise<void>;
  /** Executes a callback within a transaction, committing on success and rolling back on error. */
  transactional<T>(
    cb: (trx: Transaction<ControlledTransaction<any, any>>) => Promise<T>,
    options?: {
      isolationLevel?: IsolationLevel;
      readOnly?: boolean;
      ctx?: ControlledTransaction<any>;
      eventBroadcaster?: TransactionEventBroadcaster;
      loggerContext?: LogContext;
    },
  ): Promise<T>;
  /** Begins a new transaction or creates a savepoint if a transaction context already exists. */
  begin(options?: {
    isolationLevel?: IsolationLevel;
    readOnly?: boolean;
    ctx?: ControlledTransaction<any, any>;
    eventBroadcaster?: TransactionEventBroadcaster;
    loggerContext?: LogContext;
  }): Promise<ControlledTransaction<any, any>>;
  /** Commits the transaction or releases the savepoint. */
  commit(
    ctx: ControlledTransaction<any, any>,
    eventBroadcaster?: TransactionEventBroadcaster,
    loggerContext?: LogContext,
  ): Promise<void>;
  /** Rolls back the transaction or rolls back to the savepoint. */
  rollback(
    ctx: ControlledTransaction<any, any>,
    eventBroadcaster?: TransactionEventBroadcaster,
    loggerContext?: LogContext,
  ): Promise<void>;
  private prepareQuery;
  /** Executes a SQL query and returns the result based on the method: `'all'` for rows, `'get'` for single row, `'run'` for affected count. */
  execute<T extends QueryResult | EntityData<AnyEntity> | EntityData<AnyEntity>[] = EntityData<AnyEntity>[]>(
    query: string | NativeQueryBuilder | RawQueryFragment,
    params?: readonly unknown[],
    method?: 'all' | 'get' | 'run',
    ctx?: Transaction,
    loggerContext?: LoggingOptions,
  ): Promise<T>;
  /** Executes a SQL query and returns an async iterable that yields results row by row. */
  stream<T extends EntityData<AnyEntity>>(
    query: string | NativeQueryBuilder | RawQueryFragment,
    params?: readonly unknown[],
    ctx?: Transaction<Kysely<any>>,
    loggerContext?: LoggingOptions,
  ): AsyncIterableIterator<T>;
  /** @inheritDoc */
  executeDump(dump: string): Promise<void>;
  protected getSql(query: string, formatted: string, context?: LogContext): string;
  protected transformRawResult<T>(res: any, method?: 'all' | 'get' | 'run'): T;
}
