import { type ReceiveType, type Type } from '../reflection';
import { SqlInput, type Dialect } from './sql';
import type { DatabaseDriver, ExecuteResult } from './driver';
import { EntityClass, type EntityMetadata } from './metadata';
import { QueryBuilder } from './query';
import { DatabaseSchemaBuilder } from './schema';
import { DatabaseSession } from './session';
import type { DatabaseMutationInterceptor } from './mutation';
export type MutexKey = any;
export interface BaseDatabaseOptions {
    enableLocksTable?: boolean;
    lockTableName?: string;
}
export interface DatabaseQueryObservation {
    id: string;
    phase: 'start' | 'finish';
    db: BaseDatabase;
    sql: string;
    bindings: unknown[];
    dialect: Dialect;
    operation: 'query' | 'execute';
    startedAt: number;
    durationMs: number;
    error?: unknown;
}
export type DatabaseQueryObserver = (entry: DatabaseQueryObservation) => void;
export declare function registerDatabaseQueryObserver(observer: DatabaseQueryObserver): () => void;
export declare class BaseDatabase {
    readonly driver: DatabaseDriver;
    readonly entityRegistry: EntityClass[];
    readonly options: Required<BaseDatabaseOptions>;
    readonly schema: DatabaseSchemaBuilder;
    private readonly mutationInterceptors;
    constructor(driver: DatabaseDriver, entities?: EntityClass[], options?: BaseDatabaseOptions);
    query<T extends object>(Entity: EntityClass<T>, session?: DatabaseSession): QueryBuilder<T>;
    transaction<T>(worker: (session: DatabaseSession) => Promise<T>): Promise<T>;
    withTransaction<T>(session: DatabaseSession | undefined, worker: (session: DatabaseSession) => Promise<T>): Promise<T>;
    registerMutationInterceptor(interceptor: DatabaseMutationInterceptor): () => void;
    hasMutationInterceptorFor(metadata: EntityMetadata): boolean;
    getMutationQuerySnapshotFields(metadata: EntityMetadata): string[];
    private runMutationInterceptors;
    withConnection<T>(worker: (db: this) => Promise<T> | T): Promise<T>;
    rawQuery<T = Record<string, unknown>>(input: SqlInput, session?: DatabaseSession): Promise<T[]>;
    rawFind<T = Record<string, unknown>>(input: SqlInput, session?: DatabaseSession): Promise<T[]>;
    rawFindTyped<T>(input: SqlInput, session: DatabaseSession | undefined, type: Type): Promise<T[]>;
    rawFindOne<T = Record<string, unknown>>(input: SqlInput, session?: DatabaseSession): Promise<T | undefined>;
    createSqlQuery(text: string, bindings?: unknown[]): import("./sql").SqlQuery;
    rawExecute(input: SqlInput, session?: DatabaseSession): Promise<ExecuteResult>;
    rawFindUnsafe<T = Record<string, unknown>>(text: string, bindings?: unknown[], session?: DatabaseSession, type?: ReceiveType<T>): Promise<T[]>;
    rawFindOneUnsafe<T = Record<string, unknown>>(text: string, bindings?: unknown[], session?: DatabaseSession, type?: ReceiveType<T>): Promise<T | undefined>;
    rawExecuteUnsafe(text: string, bindings?: unknown[], session?: DatabaseSession, _type?: unknown): Promise<ExecuteResult>;
    acquireSessionLock(key: MutexKey | MutexKey[], session: DatabaseSession): Promise<void>;
    persist(entity: object, session?: DatabaseSession): Promise<void>;
    saveEntity(entity: object, session?: DatabaseSession): Promise<void>;
    deleteEntity(entity: object, session?: DatabaseSession): Promise<void>;
    private loadEntitySnapshotForUpdate;
}
export declare function ensureMySQLLocksTable(db: BaseDatabase): Promise<void>;
export declare function flattenMutexKey(key: MutexKey | MutexKey[]): string;
export declare function logSql(text: string, bindings?: unknown[]): void;
//# sourceMappingURL=database.d.ts.map