@mikro-orm/sql
Advanced tools
+13
-13
@@ -18,8 +18,8 @@ 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 LockOptions, type LoggingOptions, type NativeInsertUpdateManyOptions, type NativeInsertUpdateOptions, type ObjectQuery, type Options, type OrderDefinition, type PopulateOptions, type PopulatePath, type Primary, type QueryOrderMap, type QueryResult, RawQueryFragment, type StreamOptions, type Transaction, type UpsertManyOptions, type UpsertOptions } from '@mikro-orm/core'; | ||
| private createQueryBuilderFromOptions; | ||
| find<T extends object, P extends string = never, F extends string = PopulatePath.ALL, E extends string = never>(entityName: string, where: ObjectQuery<T>, options?: FindOptions<T, P, F, E>): Promise<EntityData<T>[]>; | ||
| findOne<T extends object, P extends string = never, F extends string = PopulatePath.ALL, E extends string = never>(entityName: string, where: ObjectQuery<T>, options?: FindOneOptions<T, P, F, E>): Promise<EntityData<T> | null>; | ||
| find<T extends object, P extends string = never, F extends string = PopulatePath.ALL, E extends string = never>(entityName: EntityName<T>, where: ObjectQuery<T>, options?: FindOptions<T, P, F, E>): Promise<EntityData<T>[]>; | ||
| findOne<T extends object, P extends string = never, F extends string = PopulatePath.ALL, E extends string = never>(entityName: EntityName<T>, where: ObjectQuery<T>, options?: FindOneOptions<T, P, F, E>): Promise<EntityData<T> | null>; | ||
| protected hasToManyJoins<T extends object>(hint: PopulateOptions<T>, meta: EntityMetadata<T>): boolean; | ||
| findVirtual<T extends object>(entityName: string, where: ObjectQuery<T>, options: FindOptions<T, any, any, any>): Promise<EntityData<T>[]>; | ||
| countVirtual<T extends object>(entityName: string, where: ObjectQuery<T>, options: CountOptions<T, any>): Promise<number>; | ||
| protected findFromVirtual<T extends object>(entityName: string, where: ObjectQuery<T>, options: FindOptions<T, any> | CountOptions<T, any>, type: QueryType): Promise<EntityData<T>[] | number>; | ||
| findVirtual<T extends object>(entityName: EntityName<T>, where: ObjectQuery<T>, options: FindOptions<T, any, any, any>): Promise<EntityData<T>[]>; | ||
| countVirtual<T extends object>(entityName: EntityName<T>, where: ObjectQuery<T>, options: CountOptions<T, any>): Promise<number>; | ||
| protected findFromVirtual<T extends object>(entityName: EntityName<T>, where: ObjectQuery<T>, options: FindOptions<T, any> | CountOptions<T, any>, type: QueryType): Promise<EntityData<T>[] | number>; | ||
| protected streamFromVirtual<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, options: StreamOptions<T, any>): AsyncIterableIterator<EntityData<T>>; | ||
@@ -30,8 +30,8 @@ protected wrapVirtualExpressionInSubquery<T extends object>(meta: EntityMetadata<T>, expression: string, where: FilterQuery<T>, options: FindOptions<T, any>, type: QueryType): Promise<T[] | number>; | ||
| private mapJoinedProps; | ||
| count<T extends object>(entityName: string, where: any, options?: CountOptions<T>): Promise<number>; | ||
| nativeInsert<T extends object>(entityName: string, data: EntityDictionary<T>, options?: NativeInsertUpdateOptions<T>): Promise<QueryResult<T>>; | ||
| nativeInsertMany<T extends object>(entityName: string, data: EntityDictionary<T>[], options?: NativeInsertUpdateManyOptions<T>, transform?: (sql: string) => string): Promise<QueryResult<T>>; | ||
| nativeUpdate<T extends object>(entityName: string, where: FilterQuery<T>, data: EntityDictionary<T>, options?: NativeInsertUpdateOptions<T> & UpsertOptions<T>): Promise<QueryResult<T>>; | ||
| nativeUpdateMany<T extends object>(entityName: string, where: FilterQuery<T>[], data: EntityDictionary<T>[], options?: NativeInsertUpdateManyOptions<T> & UpsertManyOptions<T>): Promise<QueryResult<T>>; | ||
| nativeDelete<T extends object>(entityName: string, where: FilterQuery<T> | string | any, options?: DeleteOptions<T>): Promise<QueryResult<T>>; | ||
| count<T extends object>(entityName: EntityName<T>, where: any, options?: CountOptions<T>): Promise<number>; | ||
| nativeInsert<T extends object>(entityName: EntityName<T>, data: EntityDictionary<T>, options?: NativeInsertUpdateOptions<T>): Promise<QueryResult<T>>; | ||
| nativeInsertMany<T extends object>(entityName: EntityName<T>, data: EntityDictionary<T>[], options?: NativeInsertUpdateManyOptions<T>, transform?: (sql: string) => string): Promise<QueryResult<T>>; | ||
| nativeUpdate<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, data: EntityDictionary<T>, options?: NativeInsertUpdateOptions<T> & UpsertOptions<T>): Promise<QueryResult<T>>; | ||
| nativeUpdateMany<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>[], data: EntityDictionary<T>[], options?: NativeInsertUpdateManyOptions<T> & UpsertManyOptions<T>): Promise<QueryResult<T>>; | ||
| nativeDelete<T extends object>(entityName: EntityName<T>, where: FilterQuery<T> | string | any, options?: DeleteOptions<T>): Promise<QueryResult<T>>; | ||
| /** | ||
@@ -74,4 +74,4 @@ * Fast comparison for collection snapshots that are represented by PK arrays. | ||
| }): ConnectionType; | ||
| protected extractManyToMany<T>(entityName: string, data: EntityDictionary<T>): EntityData<T>; | ||
| protected processManyToMany<T extends object>(meta: EntityMetadata<T> | undefined, pks: Primary<T>[], collections: EntityData<T>, clear: boolean, options?: DriverMethodOptions): Promise<void>; | ||
| protected extractManyToMany<T>(meta: EntityMetadata<T>, data: EntityDictionary<T>): EntityData<T>; | ||
| protected processManyToMany<T extends object>(meta: EntityMetadata<T>, pks: Primary<T>[], collections: EntityData<T>, clear: boolean, options?: DriverMethodOptions): Promise<void>; | ||
| lockPessimistic<T extends object>(entity: T, options: LockOptions): Promise<void>; | ||
@@ -78,0 +78,0 @@ protected buildPopulateWhere<T extends object>(meta: EntityMetadata<T>, joinedProps: PopulateOptions<T>[], options: Pick<FindOptions<any>, 'populateWhere'>): ObjectQuery<T>; |
+2
-2
| { | ||
| "name": "@mikro-orm/sql", | ||
| "version": "7.0.0-dev.114", | ||
| "version": "7.0.0-dev.115", | ||
| "description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.", | ||
@@ -59,4 +59,4 @@ "type": "module", | ||
| "peerDependencies": { | ||
| "@mikro-orm/core": "7.0.0-dev.114" | ||
| "@mikro-orm/core": "7.0.0-dev.115" | ||
| } | ||
| } |
@@ -123,3 +123,3 @@ class InsertStatement { | ||
| } | ||
| await this.driver.nativeDelete(this.meta.className, cond, { | ||
| await this.driver.nativeDelete(this.meta.class, cond, { | ||
| ctx: this.ctx, | ||
@@ -135,3 +135,3 @@ schema: this.schema, | ||
| const chunk = filtered.slice(i, i + this.batchSize); | ||
| await this.driver.nativeInsertMany(this.meta.className, chunk, { | ||
| await this.driver.nativeInsertMany(this.meta.class, chunk, { | ||
| ctx: this.ctx, | ||
@@ -149,3 +149,3 @@ schema: this.schema, | ||
| const chunk = filtered.slice(i, i + this.batchSize); | ||
| await this.driver.nativeUpdateMany(this.meta.className, [], chunk, { | ||
| await this.driver.nativeUpdateMany(this.meta.class, [], chunk, { | ||
| ctx: this.ctx, | ||
@@ -152,0 +152,0 @@ schema: this.schema, |
@@ -709,3 +709,3 @@ import { ReferenceKind, isRaw, } from '@mikro-orm/core'; | ||
| findEntityMetadata(name) { | ||
| const byEntity = this.metadata.find(name); | ||
| const byEntity = this.metadata.getByClassName(name, false); | ||
| if (byEntity) { | ||
@@ -712,0 +712,0 @@ return byEntity; |
@@ -1,2 +0,2 @@ | ||
| import { type EntityKey, type EntityProperty, type MetadataStorage, type RawQueryFragmentSymbol } from '@mikro-orm/core'; | ||
| import { type EntityKey, type EntityProperty, type MetadataStorage, type RawQueryFragmentSymbol, type EntityName } from '@mikro-orm/core'; | ||
| import type { ICriteriaNode, ICriteriaNodeProcessOptions, IQueryBuilder } from '../typings.js'; | ||
@@ -10,3 +10,3 @@ /** | ||
| protected readonly metadata: MetadataStorage; | ||
| readonly entityName: string; | ||
| readonly entityName: EntityName<T>; | ||
| readonly parent?: ICriteriaNode<T> | undefined; | ||
@@ -18,3 +18,3 @@ readonly key?: (EntityKey<T> | RawQueryFragmentSymbol) | undefined; | ||
| index?: number; | ||
| constructor(metadata: MetadataStorage, entityName: string, parent?: ICriteriaNode<T> | undefined, key?: (EntityKey<T> | RawQueryFragmentSymbol) | undefined, validate?: boolean, strict?: boolean); | ||
| constructor(metadata: MetadataStorage, entityName: EntityName<T>, parent?: ICriteriaNode<T> | undefined, key?: (EntityKey<T> | RawQueryFragmentSymbol) | undefined, validate?: boolean, strict?: boolean); | ||
| process(qb: IQueryBuilder<T>, options?: ICriteriaNodeProcessOptions): any; | ||
@@ -21,0 +21,0 @@ unwrap(): any; |
@@ -33,3 +33,3 @@ import { RawQueryFragment, ReferenceKind, Utils, inspect, } from '@mikro-orm/core'; | ||
| if (validate && !isProp && !k.includes('.') && !k.includes('::') && !Utils.isOperator(k)) { | ||
| throw new Error(`Trying to query by not existing property ${entityName}.${k}`); | ||
| throw new Error(`Trying to query by not existing property ${Utils.className(entityName)}.${k}`); | ||
| } | ||
@@ -83,3 +83,3 @@ } | ||
| const addParentIndex = this.prop && [ReferenceKind.ONE_TO_MANY, ReferenceKind.MANY_TO_MANY].includes(this.prop.kind); | ||
| const parentPath = this.parent?.getPath(addParentIndex) ?? this.entityName; | ||
| const parentPath = this.parent?.getPath(addParentIndex) ?? Utils.className(this.entityName); | ||
| const index = addIndex && this.index != null ? `[${this.index}]` : ''; | ||
@@ -114,2 +114,3 @@ // ignore group operators to allow easier mapping (e.g. for orderBy) | ||
| /** @ignore */ | ||
| /* v8 ignore next */ | ||
| [Symbol.for('nodejs.util.inspect.custom')]() { | ||
@@ -116,0 +117,0 @@ const o = {}; |
@@ -1,2 +0,2 @@ | ||
| import { type Dictionary, type EntityKey, type EntityMetadata, type MetadataStorage, type RawQueryFragmentSymbol } from '@mikro-orm/core'; | ||
| import { type Dictionary, type EntityKey, type EntityMetadata, type EntityName, type MetadataStorage, type RawQueryFragmentSymbol } from '@mikro-orm/core'; | ||
| import type { ICriteriaNode } from '../typings.js'; | ||
@@ -7,7 +7,7 @@ /** | ||
| export declare class CriteriaNodeFactory { | ||
| static createNode<T extends object>(metadata: MetadataStorage, entityName: string, payload: any, parent?: ICriteriaNode<T>, key?: EntityKey<T> | RawQueryFragmentSymbol): ICriteriaNode<T>; | ||
| static createScalarNode<T extends object>(metadata: MetadataStorage, entityName: string, payload: any, parent?: ICriteriaNode<T>, key?: EntityKey<T> | RawQueryFragmentSymbol): ICriteriaNode<T>; | ||
| static createArrayNode<T extends object>(metadata: MetadataStorage, entityName: string, payload: any[], parent?: ICriteriaNode<T>, key?: EntityKey<T>): ICriteriaNode<T>; | ||
| static createObjectNode<T extends object>(metadata: MetadataStorage, entityName: string, payload: Dictionary, parent?: ICriteriaNode<T>, key?: EntityKey<T>): ICriteriaNode<T>; | ||
| static createObjectItemNode<T extends object>(metadata: MetadataStorage, entityName: string, node: ICriteriaNode<T>, payload: Dictionary, key: EntityKey<T> | RawQueryFragmentSymbol, meta?: EntityMetadata<T>): ICriteriaNode<T>; | ||
| static createNode<T extends object>(metadata: MetadataStorage, entityName: EntityName<T>, payload: any, parent?: ICriteriaNode<T>, key?: EntityKey<T> | RawQueryFragmentSymbol): ICriteriaNode<T>; | ||
| static createScalarNode<T extends object>(metadata: MetadataStorage, entityName: EntityName<T>, payload: any, parent?: ICriteriaNode<T>, key?: EntityKey<T> | RawQueryFragmentSymbol): ICriteriaNode<T>; | ||
| static createArrayNode<T extends object>(metadata: MetadataStorage, entityName: EntityName<T>, payload: any[], parent?: ICriteriaNode<T>, key?: EntityKey<T>): ICriteriaNode<T>; | ||
| static createObjectNode<T extends object>(metadata: MetadataStorage, entityName: EntityName<T>, payload: Dictionary, parent?: ICriteriaNode<T>, key?: EntityKey<T>): ICriteriaNode<T>; | ||
| static createObjectItemNode<T extends object>(metadata: MetadataStorage, entityName: EntityName<T>, node: ICriteriaNode<T>, payload: Dictionary, key: EntityKey<T> | RawQueryFragmentSymbol, meta?: EntityMetadata<T>): ICriteriaNode<T>; | ||
| } |
@@ -49,3 +49,3 @@ import { GroupOperator, isRaw, JsonType, RawQueryFragment, ReferenceKind, Utils, ValidationError, } from '@mikro-orm/core'; | ||
| const prop = rawField ? null : meta?.properties[key]; | ||
| const childEntity = prop && prop.kind !== ReferenceKind.SCALAR ? prop.type : entityName; | ||
| const childEntity = prop && prop.kind !== ReferenceKind.SCALAR ? prop.targetMeta.class : entityName; | ||
| const isNotEmbedded = rawField || prop?.kind !== ReferenceKind.EMBEDDED; | ||
@@ -52,0 +52,0 @@ const val = payload[key]; |
@@ -40,4 +40,4 @@ import { ALIAS_REPLACEMENT, GroupOperator, QueryFlag, raw, RawQueryFragment, ReferenceKind, Utils, } from '@mikro-orm/core'; | ||
| const sub = qb2 | ||
| .from(parentMeta.className) | ||
| .innerJoin(this.key, qb2.getNextAlias(this.prop.type)) | ||
| .from(parentMeta.class) | ||
| .innerJoin(this.key, qb2.getNextAlias(this.prop.targetMeta.class)) | ||
| .select(parentMeta.primaryKeys); | ||
@@ -104,3 +104,3 @@ if (key === '$every') { | ||
| else { | ||
| this.inlineCondition(`${alias}.${field}`, o, payload); | ||
| this.inlineCondition(`${alias ?? qb.alias}.${field}`, o, payload); | ||
| } | ||
@@ -222,3 +222,3 @@ return o; | ||
| autoJoin(qb, alias, options) { | ||
| const nestedAlias = qb.getNextAlias(this.prop?.pivotTable ?? this.entityName); | ||
| const nestedAlias = qb.getNextAlias(this.prop?.pivotEntity ?? this.entityName); | ||
| const rawField = RawQueryFragment.isKnownFragmentSymbol(this.key); | ||
@@ -225,0 +225,0 @@ const scalar = Utils.isPrimaryKey(this.payload) || this.payload instanceof RegExp || this.payload instanceof Date || rawField; |
@@ -223,4 +223,4 @@ import { type AnyEntity, type ConnectionType, type Dictionary, type EntityData, type EntityKey, type EntityManager, type EntityMetadata, type EntityName, type EntityProperty, type ExpandProperty, type FilterOptions, type FlushMode, type GroupOperator, type Loaded, LockMode, type LoggingOptions, type MetadataStorage, type ObjectQuery, PopulateHint, type PopulateOptions, type QBFilterQuery, type QBQueryOrderMap, QueryFlag, type QueryOrderMap, type QueryResult, RawQueryFragment, type RequiredEntityData, type Transaction } from '@mikro-orm/core'; | ||
| */ | ||
| from<Entity extends AnyEntity<Entity> = AnyEntity>(target: QueryBuilder<Entity>, aliasName?: string): SelectQueryBuilder<Entity, RootAlias, Hint, Context>; | ||
| from<Entity extends AnyEntity<Entity> = AnyEntity>(target: EntityName<Entity>): SelectQueryBuilder<Entity, RootAlias, Hint, Context>; | ||
| from<Entity extends object>(target: QueryBuilder<Entity>, aliasName?: string): SelectQueryBuilder<Entity, RootAlias, Hint, Context>; | ||
| from<Entity extends object>(target: EntityName<Entity>): SelectQueryBuilder<Entity, RootAlias, Hint, Context>; | ||
| getNativeQuery(processVirtualEntity?: boolean): NativeQueryBuilder; | ||
@@ -258,7 +258,7 @@ /** | ||
| */ | ||
| getNextAlias(entityName?: string): string; | ||
| getNextAlias(entityName?: string | EntityName): string; | ||
| /** | ||
| * @internal | ||
| */ | ||
| getAliasMap(): Dictionary<string>; | ||
| getAliasMap(): Dictionary<EntityName>; | ||
| /** | ||
@@ -312,5 +312,9 @@ * Executes this QB and returns the raw results, mapped to the property names (unless disabled via last parameter). | ||
| * Returns native query builder instance with sub-query aliased with given alias. | ||
| * You can provide `EntityName.propName` as alias, then the field name will be used based on the metadata | ||
| */ | ||
| as(alias: string): NativeQueryBuilder; | ||
| /** | ||
| * Returns native query builder instance with sub-query aliased with given alias. | ||
| * You can provide the target entity name as the first parameter and use the second parameter to point to an existing property to infer its field name. | ||
| */ | ||
| as<T>(targetEntity: EntityName<T>, alias: EntityKey<T>): NativeQueryBuilder; | ||
| clone(reset?: boolean | string[]): QueryBuilder<Entity>; | ||
@@ -317,0 +321,0 @@ /** |
+50
-51
@@ -1,2 +0,2 @@ | ||
| import { helper, isRaw, LoadStrategy, LockMode, PopulateHint, QueryFlag, QueryHelper, raw, RawQueryFragment, Reference, ReferenceKind, serialize, Utils, ValidationError, inspect, } from '@mikro-orm/core'; | ||
| import { helper, inspect, isRaw, LoadStrategy, LockMode, PopulateHint, QueryFlag, QueryHelper, raw, RawQueryFragment, Reference, ReferenceKind, serialize, Utils, ValidationError, } from '@mikro-orm/core'; | ||
| import { JoinType, QueryType } from './enums.js'; | ||
@@ -141,3 +141,3 @@ import { QueryBuilderHelper } from './QueryBuilderHelper.js'; | ||
| else if (distinct || this.hasToManyJoins()) { | ||
| this._fields = this.mainAlias.metadata.primaryKeys; | ||
| this._fields = this.mainAlias.meta.primaryKeys; | ||
| } | ||
@@ -278,3 +278,3 @@ else { | ||
| filterOptions = QueryHelper.mergePropertyFilters(join.prop.filters, filterOptions); | ||
| const cond = await em.applyFilters(join.prop.type, join.cond, filterOptions, 'read'); | ||
| const cond = await em.applyFilters(join.prop.targetMeta.class, join.cond, filterOptions, 'read'); | ||
| if (Utils.hasObjectKeys(cond) || RawQueryFragment.hasObjectFragments(cond)) { | ||
@@ -336,3 +336,3 @@ // remove nested filters, we only care about scalars here, nesting would require another join branch | ||
| this.setFlag(this.type === QueryType.UPDATE ? QueryFlag.UPDATE_SUB_QUERY : QueryFlag.DELETE_SUB_QUERY); | ||
| this.select(this.mainAlias.metadata.primaryKeys, true); | ||
| this.select(this.mainAlias.meta.primaryKeys, true); | ||
| } | ||
@@ -385,2 +385,3 @@ if (topLevel) { | ||
| this._orderBy.push(CriteriaNodeFactory.createNode(this.metadata, this.mainAlias.entityName, processed).process(this, { matchPopulateJoins: true, type: 'orderBy' })); | ||
| // this._orderBy.push(CriteriaNodeFactory.createNode<Entity>(this.metadata, Utils.className(this.mainAlias.entityName), processed).process(this, { matchPopulateJoins: true, type: 'orderBy' })); | ||
| }); | ||
@@ -416,3 +417,3 @@ return this; | ||
| onConflict(fields = []) { | ||
| const meta = this.mainAlias.metadata; | ||
| const meta = this.mainAlias.meta; | ||
| this.ensureNotFinalized(); | ||
@@ -544,7 +545,6 @@ this._onConflict ??= []; | ||
| else { | ||
| const entityName = Utils.className(target); | ||
| if (aliasName && this._mainAlias && entityName !== this._mainAlias.aliasName) { | ||
| if (aliasName && this._mainAlias && Utils.className(target) !== this._mainAlias.aliasName) { | ||
| throw new Error(`Cannot override the alias to '${aliasName}' since a query already contains references to '${this._mainAlias.aliasName}'`); | ||
| } | ||
| this.fromEntityName(entityName, aliasName); | ||
| this.fromEntityName(target, aliasName); | ||
| } | ||
@@ -580,3 +580,3 @@ return this; | ||
| } | ||
| this.helper.finalize(this.type, qb, this.mainAlias.metadata, this._data, this._returning); | ||
| this.helper.finalize(this.type, qb, this.mainAlias.meta, this._data, this._returning); | ||
| return this._query.qb = qb; | ||
@@ -623,3 +623,3 @@ } | ||
| getAliasForJoinPath(path, options) { | ||
| if (!path || path === this.mainAlias.entityName) { | ||
| if (!path || path === Utils.className(this.mainAlias.entityName)) { | ||
| return this.mainAlias.aliasName; | ||
@@ -668,2 +668,3 @@ } | ||
| getNextAlias(entityName = 'e') { | ||
| entityName = Utils.className(entityName); | ||
| return this.driver.config.getNamingStrategy().aliasName(entityName, this.aliasCounter++); | ||
@@ -700,3 +701,3 @@ } | ||
| const res = await this.getConnection().execute(query.sql, query.params, method, this.context, loggerContext); | ||
| const meta = this.mainAlias.metadata; | ||
| const meta = this.mainAlias.meta; | ||
| if (!options.mapResults || !meta) { | ||
@@ -715,3 +716,3 @@ await this.em?.storeCache(this._cache, cached, res); | ||
| if (options.mergeResults && joinedProps.length > 0) { | ||
| mapped = this.driver.mergeJoinedResult(mapped, this.mainAlias.metadata, joinedProps); | ||
| mapped = this.driver.mergeJoinedResult(mapped, this.mainAlias.meta, joinedProps); | ||
| } | ||
@@ -757,3 +758,3 @@ } | ||
| const res = this.getConnection().stream(query.sql, query.params, this.context, loggerContext); | ||
| const meta = this.mainAlias.metadata; | ||
| const meta = this.mainAlias.meta; | ||
| if (options.rawResults || !meta) { | ||
@@ -775,3 +776,3 @@ yield* res; | ||
| if (stack.length > 0 && hash(stack[stack.length - 1]) !== hash(mapped)) { | ||
| const res = this.driver.mergeJoinedResult(stack, this.mainAlias.metadata, joinedProps); | ||
| const res = this.driver.mergeJoinedResult(stack, this.mainAlias.meta, joinedProps); | ||
| for (const row of res) { | ||
@@ -785,3 +786,3 @@ yield this.mapResult(row, options.mapResults); | ||
| if (stack.length > 0) { | ||
| const merged = this.driver.mergeJoinedResult(stack, this.mainAlias.metadata, joinedProps); | ||
| const merged = this.driver.mergeJoinedResult(stack, this.mainAlias.meta, joinedProps); | ||
| yield this.mapResult(merged[0], options.mapResults); | ||
@@ -873,17 +874,17 @@ } | ||
| } | ||
| /** | ||
| * Returns native query builder instance with sub-query aliased with given alias. | ||
| * You can provide `EntityName.propName` as alias, then the field name will be used based on the metadata | ||
| */ | ||
| as(alias) { | ||
| as(aliasOrTargetEntity, alias) { | ||
| const qb = this.getNativeQuery(); | ||
| if (alias.includes('.')) { | ||
| const [a, f] = alias.split('.'); | ||
| const meta = this.metadata.find(a); | ||
| let finalAlias = aliasOrTargetEntity; | ||
| /* v8 ignore next */ | ||
| if (typeof aliasOrTargetEntity === 'string' && aliasOrTargetEntity.includes('.')) { | ||
| throw new Error('qb.as(alias) no longer supports target entity name prefix, use qb.as(TargetEntity, key) signature instead'); | ||
| } | ||
| if (alias) { | ||
| const meta = this.metadata.get(aliasOrTargetEntity); | ||
| /* v8 ignore next */ | ||
| alias = meta?.properties[f]?.fieldNames[0] ?? alias; | ||
| finalAlias = meta.properties[alias]?.fieldNames[0] ?? alias; | ||
| } | ||
| qb.as(alias); | ||
| qb.as(finalAlias); | ||
| // tag the instance, so it is possible to detect it easily | ||
| Object.defineProperty(qb, '__as', { enumerable: false, value: alias }); | ||
| Object.defineProperty(qb, '__as', { enumerable: false, value: finalAlias }); | ||
| return qb; | ||
@@ -957,4 +958,4 @@ } | ||
| if (field instanceof QueryBuilder) { | ||
| prop.type = field.mainAlias.entityName; | ||
| prop.targetMeta = field.mainAlias.metadata; | ||
| prop.type = Utils.className(field.mainAlias.entityName); | ||
| prop.targetMeta = field.mainAlias.meta; | ||
| field = field.getNativeQuery(); | ||
@@ -991,3 +992,3 @@ } | ||
| } | ||
| this.createAlias(prop.type, alias); | ||
| this.createAlias(prop.targetMeta.class, alias); | ||
| cond = QueryHelper.processWhere({ | ||
@@ -1001,6 +1002,6 @@ where: cond, | ||
| }); | ||
| const criteriaNode = CriteriaNodeFactory.createNode(this.metadata, prop.targetMeta.className, cond); | ||
| const criteriaNode = CriteriaNodeFactory.createNode(this.metadata, prop.targetMeta.class, cond); | ||
| cond = criteriaNode.process(this, { ignoreBranching: true, alias }); | ||
| let aliasedName = `${fromAlias}.${prop.name}#${alias}`; | ||
| path ??= `${(Object.values(this._joins).find(j => j.alias === fromAlias)?.path ?? entityName)}.${prop.name}`; | ||
| path ??= `${(Object.values(this._joins).find(j => j.alias === fromAlias)?.path ?? Utils.className(entityName))}.${prop.name}`; | ||
| if (prop.kind === ReferenceKind.ONE_TO_MANY) { | ||
@@ -1083,5 +1084,3 @@ this._joins[aliasedName] = this.helper.joinOneToReference(prop, fromAlias, alias, type, cond, schema); | ||
| }); | ||
| const meta = this.mainAlias.metadata; | ||
| /* v8 ignore next */ | ||
| const requiresSQLConversion = meta?.props.filter(p => p.hasConvertToJSValueSQL && p.persist !== false) ?? []; | ||
| const requiresSQLConversion = this.mainAlias.meta.props.filter(p => p.hasConvertToJSValueSQL && p.persist !== false); | ||
| if (this.flags.has(QueryFlag.CONVERT_CUSTOM_TYPES) && (fields.includes('*') || fields.includes(`${this.mainAlias.aliasName}.*`)) && requiresSQLConversion.length > 0) { | ||
@@ -1121,3 +1120,3 @@ for (const p of requiresSQLConversion) { | ||
| const qb = this.platform.createNativeQueryBuilder().setFlags(this.flags); | ||
| const { subQuery, aliasName, entityName, metadata } = this.mainAlias; | ||
| const { subQuery, aliasName, entityName, meta } = this.mainAlias; | ||
| const requiresAlias = this.finalized && (this._explicitAlias || this.helper.isTableNameAliasRequired(this.type)); | ||
@@ -1128,4 +1127,4 @@ const alias = requiresAlias ? aliasName : undefined; | ||
| const joinSchema = this._schema ?? this.em?.schema ?? schema; | ||
| if (metadata?.virtual && processVirtualEntity) { | ||
| qb.from(raw(this.fromVirtual(metadata)), { indexHint: this._indexHint }); | ||
| if (meta.virtual && processVirtualEntity) { | ||
| qb.from(raw(this.fromVirtual(meta)), { indexHint: this._indexHint }); | ||
| } | ||
@@ -1174,15 +1173,15 @@ else { | ||
| applyDiscriminatorCondition() { | ||
| const meta = this.mainAlias.metadata; | ||
| if (!meta?.discriminatorValue) { | ||
| const meta = this.mainAlias.meta; | ||
| if (!meta.discriminatorValue) { | ||
| return; | ||
| } | ||
| const types = Object.values(meta.root.discriminatorMap).map(cls => this.metadata.find(cls)); | ||
| const types = Object.values(meta.root.discriminatorMap).map(cls => this.metadata.get(cls)); | ||
| const children = []; | ||
| const lookUpChildren = (ret, type) => { | ||
| const children = types.filter(meta2 => meta2.extends === type); | ||
| children.forEach(m => lookUpChildren(ret, m.className)); | ||
| children.forEach(m => lookUpChildren(ret, m.class)); | ||
| ret.push(...children.filter(c => c.discriminatorValue)); | ||
| return children; | ||
| }; | ||
| lookUpChildren(children, meta.className); | ||
| lookUpChildren(children, meta.class); | ||
| this.andWhere({ | ||
@@ -1199,3 +1198,3 @@ [meta.root.discriminatorColumn]: children.length > 0 ? { $in: [meta.discriminatorValue, ...children.map(c => c.discriminatorValue)] } : meta.discriminatorValue, | ||
| } | ||
| const meta = this.mainAlias.metadata; | ||
| const meta = this.mainAlias.meta; | ||
| this.applyDiscriminatorCondition(); | ||
@@ -1240,3 +1239,3 @@ this.processPopulateHint(); | ||
| } | ||
| const meta = this.mainAlias.metadata; | ||
| const meta = this.mainAlias.meta; | ||
| if (meta && this.flags.has(QueryFlag.AUTO_JOIN_ONE_TO_ONE_OWNER)) { | ||
@@ -1259,3 +1258,3 @@ const relationsToPopulate = this._populate.map(({ field }) => field); | ||
| const prop = meta.properties[fromField]; | ||
| const alias = this.getNextAlias(prop.pivotEntity ?? prop.type); | ||
| const alias = this.getNextAlias(prop.pivotEntity ?? prop.targetMeta.class); | ||
| const aliasedName = `${fromAlias}.${prop.name}#${alias}`; | ||
@@ -1265,3 +1264,3 @@ this._joins[aliasedName] = this.helper.joinOneToReference(prop, this.mainAlias.aliasName, alias, JoinType.leftJoin); | ||
| this._populateMap[aliasedName] = this._joins[aliasedName].alias; | ||
| this.createAlias(prop.type, alias); | ||
| this.createAlias(prop.targetMeta.class, alias); | ||
| } | ||
@@ -1492,4 +1491,4 @@ }); | ||
| getSchema(alias) { | ||
| const { metadata } = alias; | ||
| const metaSchema = metadata?.schema && metadata.schema !== '*' ? metadata.schema : undefined; | ||
| const { meta } = alias; | ||
| const metaSchema = meta.schema && meta.schema !== '*' ? meta.schema : undefined; | ||
| const schema = this._schema ?? metaSchema ?? this.em?.schema ?? this.em?.config.getSchema(true); | ||
@@ -1502,4 +1501,4 @@ if (schema === this.platform.getDefaultSchemaName()) { | ||
| createAlias(entityName, aliasName, subQuery) { | ||
| const metadata = this.metadata.find(entityName); | ||
| const alias = { aliasName, entityName, metadata, subQuery }; | ||
| const meta = this.metadata.find(entityName); | ||
| const alias = { aliasName, entityName, meta, subQuery }; | ||
| this._aliases[aliasName] = alias; | ||
@@ -1562,3 +1561,3 @@ return alias; | ||
| } | ||
| const name = this._mainAlias ? `${prefix}QueryBuilder<${this._mainAlias?.entityName}>` : 'QueryBuilder'; | ||
| const name = this._mainAlias ? `${prefix}QueryBuilder<${Utils.className(this._mainAlias?.entityName)}>` : 'QueryBuilder'; | ||
| const ret = inspect(object, { depth }); | ||
@@ -1565,0 +1564,0 @@ return ret === '[Object]' ? `[${name}]` : name + ' ' + ret; |
@@ -1,2 +0,2 @@ | ||
| import { type Dictionary, type EntityData, type EntityKey, type EntityMetadata, type EntityProperty, type FlatQueryOrderMap, LockMode, type QBFilterQuery, type QBQueryOrderMap, Raw, type RawQueryFragmentSymbol } from '@mikro-orm/core'; | ||
| import { type Dictionary, type EntityData, type EntityKey, type EntityMetadata, type EntityName, type EntityProperty, type FlatQueryOrderMap, LockMode, type QBFilterQuery, type QBQueryOrderMap, Raw, type RawQueryFragmentSymbol } from '@mikro-orm/core'; | ||
| import { JoinType, QueryType } from './enums.js'; | ||
@@ -17,3 +17,3 @@ import type { Field, JoinOptions } from '../typings.js'; | ||
| private readonly metadata; | ||
| constructor(entityName: string, alias: string, aliasMap: Dictionary<Alias<any>>, subQueries: Dictionary<string>, driver: AbstractSqlDriver); | ||
| constructor(entityName: EntityName, alias: string, aliasMap: Dictionary<Alias<any>>, subQueries: Dictionary<string>, driver: AbstractSqlDriver); | ||
| mapper(field: string | Raw | RawQueryFragmentSymbol, type?: QueryType): string; | ||
@@ -32,3 +32,3 @@ mapper(field: string | Raw | RawQueryFragmentSymbol, type?: QueryType, value?: any, alias?: string | null): string; | ||
| isOneToOneInverse(field: string, meta?: EntityMetadata): boolean; | ||
| getTableName(entityName: string): string; | ||
| getTableName(entityName: EntityName): string; | ||
| /** | ||
@@ -67,4 +67,4 @@ * Checks whether the RE can be rewritten to simple LIKE query | ||
| aliasName: string; | ||
| entityName: string; | ||
| metadata?: EntityMetadata<T>; | ||
| entityName: EntityName<T>; | ||
| meta: EntityMetadata<T>; | ||
| subQuery?: NativeQueryBuilder; | ||
@@ -71,0 +71,0 @@ } |
@@ -131,3 +131,3 @@ import { ALIAS_REPLACEMENT, ALIAS_REPLACEMENT_RE, ArrayType, inspect, isRaw, LockMode, OptimisticLockError, QueryOperator, QueryOrderNumeric, raw, Raw, ReferenceKind, Utils, ValidationError, } from '@mikro-orm/core'; | ||
| const prop2 = prop.targetMeta.properties[prop.mappedBy || prop.inversedBy]; | ||
| const table = this.getTableName(prop.type); | ||
| const table = this.getTableName(prop.targetMeta.class); | ||
| const joinColumns = prop.owner ? prop.referencedColumnNames : prop2.joinColumns; | ||
@@ -146,3 +146,3 @@ const inverseJoinColumns = prop.referencedColumnNames; | ||
| prop, type, cond, ownerAlias, alias, | ||
| table: this.getTableName(prop.type), | ||
| table: this.getTableName(prop.targetMeta.class), | ||
| schema: prop.targetMeta?.schema === '*' ? '*' : this.driver.getSchemaName(prop.targetMeta, { schema }), | ||
@@ -172,3 +172,3 @@ joinColumns: prop.referencedColumnNames, | ||
| } | ||
| const prop2 = prop.owner ? pivotMeta.relations[1] : pivotMeta.relations[0]; | ||
| const prop2 = pivotMeta.relations[prop.owner ? 1 : 0]; | ||
| ret[`${pivotAlias}.${prop2.name}#${alias}`] = this.joinManyToOneReference(prop2, pivotAlias, alias, type, cond, schema); | ||
@@ -270,3 +270,3 @@ ret[`${pivotAlias}.${prop2.name}#${alias}`].path = path; | ||
| const meta = this.metadata.find(entityName); | ||
| return meta ? meta.collection : entityName; | ||
| return meta?.tableName ?? Utils.className(entityName); | ||
| } | ||
@@ -651,3 +651,3 @@ /** | ||
| if (lockMode === LockMode.OPTIMISTIC && meta && !meta.versionProperty) { | ||
| throw OptimisticLockError.lockFailed(this.entityName); | ||
| throw OptimisticLockError.lockFailed(Utils.className(this.entityName)); | ||
| } | ||
@@ -747,5 +747,5 @@ if (lockMode !== LockMode.OPTIMISTIC && lockTables.length === 0 && joinsMap) { | ||
| const entityName = this.aliasMap[alias]?.entityName || this.entityName; | ||
| const meta = this.metadata.find(entityName); | ||
| const meta = this.metadata.get(entityName); | ||
| // check if `alias` is not matching an embedded property name instead of alias, e.g. `address.city` | ||
| if (alias && meta) { | ||
| if (alias) { | ||
| const prop = meta.properties[alias]; | ||
@@ -762,9 +762,6 @@ if (prop?.kind === ReferenceKind.EMBEDDED) { | ||
| } | ||
| if (meta) { | ||
| if (meta.properties[field]) { | ||
| return meta.properties[field]; | ||
| } | ||
| return meta.relations.find(prop => prop.fieldNames?.some(name => field === name)); | ||
| if (meta.properties[field]) { | ||
| return meta.properties[field]; | ||
| } | ||
| return undefined; | ||
| return meta.relations.find(prop => prop.fieldNames?.some(name => field === name)); | ||
| } | ||
@@ -771,0 +768,0 @@ isTableNameAliasRequired(type) { |
@@ -15,3 +15,3 @@ import { ARRAY_OPERATORS, ReferenceKind } from '@mikro-orm/core'; | ||
| const parentPath = this.parent.getPath(); // the parent is always there, otherwise `shouldJoin` would return `false` | ||
| const nestedAlias = qb.getAliasForJoinPath(path) || qb.getNextAlias(this.prop?.pivotTable ?? this.entityName); | ||
| const nestedAlias = qb.getAliasForJoinPath(path) || qb.getNextAlias(this.prop?.pivotEntity ?? this.entityName); | ||
| const field = this.aliased(this.prop.name, options?.alias); | ||
@@ -18,0 +18,0 @@ const type = this.prop.kind === ReferenceKind.MANY_TO_MANY ? JoinType.pivotJoin : JoinType.leftJoin; |
@@ -117,3 +117,3 @@ import { AbstractSchemaGenerator, Utils, } from '@mikro-orm/core'; | ||
| for (const meta of this.getOrderedMetadata(schema).reverse()) { | ||
| await this.driver.createQueryBuilder(meta.className, this.em?.getTransactionContext(), 'write', false) | ||
| await this.driver.createQueryBuilder(meta.class, this.em?.getTransactionContext(), 'write', false) | ||
| .withSchema(schema) | ||
@@ -201,3 +201,3 @@ .truncate() | ||
| const fromSchema = options.fromSchema ?? (await DatabaseSchema.create(this.connection, this.platform, this.config, options.schema, schemas, undefined, this.options.skipTables)); | ||
| const wildcardSchemaTables = Object.values(this.metadata.getAll()).filter(meta => meta.schema === '*').map(meta => meta.tableName); | ||
| const wildcardSchemaTables = [...this.metadata.getAll().values()].filter(meta => meta.schema === '*').map(meta => meta.tableName); | ||
| fromSchema.prune(options.schema, wildcardSchemaTables); | ||
@@ -204,0 +204,0 @@ toSchema.prune(options.schema, wildcardSchemaTables); |
@@ -30,5 +30,5 @@ import { type EntitySchemaWithMeta, EntityManager, type AnyEntity, type ConnectionType, type EntityData, type EntityName, type EntityRepository, type GetRepository, type QueryResult, type FilterQuery, type LoggingOptions, type RawQueryFragment } from '@mikro-orm/core'; | ||
| getRepository<T extends object, U extends EntityRepository<T> = SqlEntityRepository<T>>(entityName: EntityName<T>): GetRepository<T, U>; | ||
| protected applyDiscriminatorCondition<Entity extends object>(entityName: string, where: FilterQuery<Entity>): FilterQuery<Entity>; | ||
| protected applyDiscriminatorCondition<Entity extends object>(entityName: EntityName<Entity>, where: FilterQuery<Entity>): FilterQuery<Entity>; | ||
| } | ||
| type EntitiesFromManager<TEntityManager extends EntityManager<any>> = NonNullable<TEntityManager['~entities']> extends any[] ? (Extract<NonNullable<TEntityManager['~entities']>[number], EntitySchemaWithMeta>) : never; | ||
| export {}; |
+4
-4
| import type { Generated, Kysely } from 'kysely'; | ||
| import type { DeferMode, CheckCallback, Dictionary, EntityProperty, GroupOperator, RawQueryFragment, QBFilterQuery, QueryOrderMap, Type, QueryFlag, AnyEntity, EntityName, EntitySchemaWithMeta, Primary, PrimaryProperty, Opt } from '@mikro-orm/core'; | ||
| import type { DeferMode, CheckCallback, Dictionary, EntityProperty, GroupOperator, RawQueryFragment, QBFilterQuery, QueryOrderMap, Type, QueryFlag, EntityName, EntitySchemaWithMeta, Primary, PrimaryProperty, Opt } from '@mikro-orm/core'; | ||
| import type { JoinType, QueryType } from './query/enums.js'; | ||
@@ -140,3 +140,3 @@ import type { DatabaseSchema } from './schema/DatabaseSchema.js'; | ||
| addSelect(fields: string | string[]): this; | ||
| from<T extends AnyEntity<T> = AnyEntity>(target: EntityName<T> | IQueryBuilder<T>, aliasName?: string): IQueryBuilder<T>; | ||
| from<T extends object>(target: EntityName<T> | IQueryBuilder<T>, aliasName?: string): IQueryBuilder<T>; | ||
| insert(data: any): this; | ||
@@ -165,3 +165,3 @@ update(data: any): this; | ||
| getJoinForPath(path?: string, options?: ICriteriaNodeProcessOptions): JoinOptions | undefined; | ||
| getNextAlias(entityName?: string): string; | ||
| getNextAlias(entityName?: string | EntityName<T>): string; | ||
| clone(reset?: boolean): IQueryBuilder<T>; | ||
@@ -182,3 +182,3 @@ setFlag(flag: QueryFlag): this; | ||
| export interface ICriteriaNode<T extends object> { | ||
| readonly entityName: string; | ||
| readonly entityName: EntityName<T>; | ||
| readonly parent?: ICriteriaNode<T> | undefined; | ||
@@ -185,0 +185,0 @@ readonly key?: string | symbol | undefined; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
810280
0.03%13310
-0.06%