import { type AnyEntity, type Collection, type Configuration, type ConnectionType, type Constructor, type CountOptions, DatabaseDriver, type DeleteOptions, type Dictionary, type DriverMethodOptions, type EntityData, type EntityDictionary, type EntityField, EntityManagerType, type EntityMetadata, type EntityName, type EntityProperty, type FilterQuery, type FindOneOptions, type FindOptions, type FormulaTable, type LockOptions, type LoggingOptions, type NativeInsertUpdateManyOptions, type NativeInsertUpdateOptions, type ObjectQuery, type Options, type OrderDefinition, type PopulateOptions, type PopulatePath, type Primary, type QueryOrderMap, type QueryResult, type Raw, RawQueryFragment, type StreamOptions, type Transaction, type UpsertManyOptions, type UpsertOptions, } from '@mikro-orm/core'; import type { AbstractSqlConnection } from './AbstractSqlConnection.js'; import type { AbstractSqlPlatform } from './AbstractSqlPlatform.js'; import { type AnyQueryBuilder } from './query/QueryBuilder.js'; import { type NativeQueryBuilder } from './query/NativeQueryBuilder.js'; import { QueryType } from './query/enums.js'; import { SqlEntityManager } from './SqlEntityManager.js'; import type { InternalField } from './typings.js'; /** Base class for SQL database drivers, implementing find/insert/update/delete using QueryBuilder. */ export declare abstract class AbstractSqlDriver< Connection extends AbstractSqlConnection = AbstractSqlConnection, Platform extends AbstractSqlPlatform = AbstractSqlPlatform, > extends DatabaseDriver { [EntityManagerType]: SqlEntityManager; protected readonly connection: Connection; protected readonly replicas: Connection[]; protected readonly platform: Platform; protected constructor( config: Configuration, platform: Platform, connection: Constructor, connector: string[], ); getPlatform(): Platform; /** Evaluates a formula callback, handling both string and Raw return values. */ evaluateFormula(formula: (...args: any[]) => string | Raw, columns: any, table: FormulaTable): string; /** For TPT entities, returns ownProps (columns in this table); otherwise returns all props. */ private getTableProps; /** Creates a FormulaTable object for use in formula callbacks. */ private createFormulaTable; private validateSqlOptions; createEntityManager(useContext?: boolean): this[typeof EntityManagerType]; private createQueryBuilderFromOptions; find( entityName: EntityName, where: ObjectQuery, options?: FindOptions, ): Promise[]>; findOne( entityName: EntityName, where: ObjectQuery, options?: FindOneOptions, ): Promise | null>; protected hasToManyJoins(hint: PopulateOptions, meta: EntityMetadata): boolean; findVirtual( entityName: EntityName, where: ObjectQuery, options: FindOptions, ): Promise[]>; countVirtual( entityName: EntityName, where: ObjectQuery, options: CountOptions, ): Promise; protected findFromVirtual( entityName: EntityName, where: ObjectQuery, options: FindOptions | CountOptions, type: QueryType, ): Promise[] | number>; protected streamFromVirtual( entityName: EntityName, where: FilterQuery, options: StreamOptions, ): AsyncIterableIterator>; protected wrapVirtualExpressionInSubquery( meta: EntityMetadata, expression: string, where: FilterQuery, options: FindOptions, type: QueryType, ): Promise; protected wrapVirtualExpressionInSubqueryStream( meta: EntityMetadata, expression: string, where: FilterQuery, options: FindOptions, type: QueryType.SELECT, ): AsyncIterableIterator; /** * Virtual entities have no PKs, so to-many populate joins can't be deduplicated. * Force balanced strategy to load to-many relations via separate queries. */ private forceBalancedStrategy; mapResult( result: EntityData, meta: EntityMetadata, populate?: PopulateOptions[], qb?: AnyQueryBuilder, map?: Dictionary, ): EntityData | null; /** * Maps aliased columns from TPT parent tables back to their original field names. * TPT parent columns are selected with aliases like `parent_alias__column_name`, * and need to be renamed back to `column_name` for the result mapper to work. */ private mapTPTColumns; private mapJoinedProps; /** * Maps a single property from a joined result row into the relation pojo. * Handles polymorphic FKs, composite keys, Date parsing, and embedded objects. */ private mapJoinedProp; count(entityName: EntityName, where: any, options?: CountOptions): Promise; nativeInsert( entityName: EntityName, data: EntityDictionary, options?: NativeInsertUpdateOptions, ): Promise>; nativeInsertMany( entityName: EntityName, data: EntityDictionary[], options?: NativeInsertUpdateManyOptions, transform?: (sql: string) => string, ): Promise>; nativeUpdate( entityName: EntityName, where: FilterQuery, data: EntityDictionary, options?: NativeInsertUpdateOptions & UpsertOptions, ): Promise>; nativeUpdateMany( entityName: EntityName, where: FilterQuery[], data: EntityDictionary[], options?: NativeInsertUpdateManyOptions & UpsertManyOptions, transform?: (sql: string, params: any[]) => string, ): Promise>; nativeDelete( entityName: EntityName, where: FilterQuery | string | any, options?: DeleteOptions, ): Promise>; /** * Fast comparison for collection snapshots that are represented by PK arrays. * Compares scalars via `===` and fallbacks to Utils.equals()` for more complex types like Buffer. * Always expects the same length of the arrays, since we only compare PKs of the same entity type. */ private comparePrimaryKeyArrays; syncCollections( collections: Iterable>, options?: DriverMethodOptions, ): Promise; loadFromPivotTable( prop: EntityProperty, owners: Primary[][], where?: FilterQuery, orderBy?: OrderDefinition, ctx?: Transaction, options?: FindOptions, pivotJoin?: boolean, ): Promise>; /** * Load from a polymorphic M:N pivot table. */ protected loadFromPolymorphicPivotTable( prop: EntityProperty, owners: Primary[][], where?: FilterQuery, orderBy?: OrderDefinition, ctx?: Transaction, options?: FindOptions, pivotJoin?: boolean, ): Promise>; /** * Load from owner side of polymorphic M:N (e.g., Post -> Tags) */ protected loadPolymorphicPivotOwnerSide( prop: EntityProperty, owners: Primary[][], where: FilterQuery, orderBy?: OrderDefinition, ctx?: Transaction, options?: FindOptions, pivotJoin?: boolean, inverseProp?: EntityProperty, ): Promise>; /** * Load from inverse side of polymorphic M:N (e.g., Tag -> Posts) * Uses single query with join via virtual relation on pivot. */ protected loadPolymorphicPivotInverseSide( prop: EntityProperty, owners: Primary[][], where: FilterQuery, orderBy?: OrderDefinition, ctx?: Transaction, options?: FindOptions, ): Promise>; /** * Build a map from owner PKs to their related entities from pivot table results. */ private buildPivotResultMap; private wrapPopulateFilter; private getPivotOrderBy; execute | EntityData[] = EntityData[]>( query: string | NativeQueryBuilder | RawQueryFragment, params?: any[], method?: 'all' | 'get' | 'run', ctx?: Transaction, loggerContext?: LoggingOptions, ): Promise; stream( entityName: EntityName, where: FilterQuery, options: StreamOptions, ): AsyncIterableIterator; /** * 1:1 owner side needs to be marked for population so QB auto-joins the owner id */ protected autoJoinOneToOneOwner( meta: EntityMetadata, populate: PopulateOptions[], fields?: readonly EntityField[], ): PopulateOptions[]; /** * @internal */ joinedProps( meta: EntityMetadata, populate: readonly PopulateOptions[], options?: { strategy?: Options['loadStrategy']; }, ): PopulateOptions[]; /** * @internal */ mergeJoinedResult( rawResults: EntityData[], meta: EntityMetadata, joinedProps: PopulateOptions[], ): EntityData[]; protected shouldHaveColumn( meta: EntityMetadata, prop: EntityProperty, populate: readonly PopulateOptions[], fields?: readonly InternalField[], exclude?: readonly InternalField[], ): boolean; protected getFieldsForJoinedLoad( qb: AnyQueryBuilder, meta: EntityMetadata, options: FieldsForJoinedLoadOptions, ): InternalField[]; /** * Adds LEFT JOINs and fields for TPT polymorphic loading when populating a relation to a TPT base class. * @internal */ protected addTPTPolymorphicJoinsForRelation( qb: AnyQueryBuilder, meta: EntityMetadata, baseAlias: string, fields: InternalField[], ): void; /** * Find the alias for a TPT child table in the query builder. * @internal */ protected findTPTChildAlias(qb: AnyQueryBuilder, childMeta: EntityMetadata): string | undefined; /** * Builds a CASE WHEN expression for TPT discriminator. * Determines concrete entity type based on which child table has a non-null PK. * @internal */ buildTPTDiscriminatorExpression( meta: EntityMetadata, descendants: EntityMetadata[], aliasMap: Dictionary, baseAlias: string, ): Raw; /** * Maps TPT child-specific fields during hydration. * When a relation points to a TPT base class, the actual entity might be a child class. * This method reads the discriminator to determine the concrete type and maps child-specific fields. * @internal */ protected mapTPTChildFields( relationPojo: EntityData, meta: EntityMetadata, relationAlias: string, qb: AnyQueryBuilder, root: EntityData, ): void; /** * @internal */ mapPropToFieldNames( qb: AnyQueryBuilder, prop: EntityProperty, tableAlias: string, meta: EntityMetadata, schema?: string, explicitFields?: readonly InternalField[], ): InternalField[]; /** @internal */ createQueryBuilder( entityName: EntityName | AnyQueryBuilder, ctx?: Transaction, preferredConnectionType?: ConnectionType, convertCustomTypes?: boolean, loggerContext?: LoggingOptions, alias?: string, em?: SqlEntityManager, ): AnyQueryBuilder; protected resolveConnectionType(args: { ctx?: Transaction; connectionType?: ConnectionType }): ConnectionType; protected extractManyToMany(meta: EntityMetadata, data: EntityDictionary): EntityData; protected processManyToMany( meta: EntityMetadata, pks: Primary[], collections: EntityData, clear: boolean, options?: DriverMethodOptions, ): Promise; lockPessimistic(entity: T, options: LockOptions): Promise; protected buildPopulateWhere( meta: EntityMetadata, joinedProps: PopulateOptions[], options: Pick, 'populateWhere'>, ): ObjectQuery; /** * Builds a UNION ALL (or UNION) subquery from `unionWhere` branches and merges it * into the main WHERE as `pk IN (branch_1 UNION ALL branch_2 ...)`. * Each branch is planned independently by the database, enabling per-table index usage. */ protected applyUnionWhere( meta: EntityMetadata, where: ObjectQuery, options: FindOptions | CountOptions | NativeInsertUpdateOptions | DeleteOptions, forDml?: boolean, ): Promise>; protected buildOrderBy( qb: AnyQueryBuilder, meta: EntityMetadata, populate: PopulateOptions[], options: Pick, 'strategy' | 'orderBy' | 'populateOrderBy'>, ): QueryOrderMap[]; protected buildPopulateOrderBy( qb: AnyQueryBuilder, meta: EntityMetadata, populateOrderBy: QueryOrderMap[], parentPath: string, explicit: boolean, parentAlias?: string, ): QueryOrderMap[]; protected buildJoinedPropsOrderBy( qb: AnyQueryBuilder, meta: EntityMetadata, populate: PopulateOptions[], options?: Pick, 'strategy' | 'orderBy' | 'populateOrderBy'>, parentPath?: string, ): QueryOrderMap[]; private buildToManyOrderBy; protected normalizeFields(fields: InternalField[], prefix?: string): string[]; protected processField( meta: EntityMetadata, prop: EntityProperty | undefined, field: string, ret: InternalField[], ): void; protected buildFields( meta: EntityMetadata, populate: PopulateOptions[], joinedProps: PopulateOptions[], qb: AnyQueryBuilder, alias: string, options: Pick, 'strategy' | 'fields' | 'exclude'>, schema?: string, ): InternalField[]; } interface FieldsForJoinedLoadOptions { explicitFields?: readonly InternalField[]; exclude?: readonly InternalField[]; populate?: readonly PopulateOptions[]; strategy?: Options['loadStrategy']; populateWhere?: FindOptions['populateWhere']; populateFilter?: FindOptions['populateFilter']; parentTableAlias: string; parentJoinPath?: string; count?: boolean; schema?: string; } export {};