MCPcopy Create free account
hub / github.com/mikro-orm/mikro-orm / init

Method init

packages/sql/src/query/QueryBuilder.ts:3357–3384  ·  view source on GitHub ↗
(type: QueryType, data?: any, cond?: any)

Source from the content-addressed store, hash-verified

3355 }
3356
3357 protected init(type: QueryType, data?: any, cond?: any): this {
3358 this.ensureNotFinalized();
3359 this.#state.type = type;
3360
3361 if ([QueryType.UPDATE, QueryType.DELETE].includes(type) && Utils.hasObjectKeys(this.#state.cond)) {
3362 throw new Error(
3363 `You are trying to call \`qb.where().${type.toLowerCase()}()\`. Calling \`qb.${type.toLowerCase()}()\` before \`qb.where()\` is required.`,
3364 );
3365 }
3366
3367 if (!this.helper.isTableNameAliasRequired(type)) {
3368 this.#state.fields = undefined;
3369 }
3370
3371 if (data) {
3372 if (Utils.isEntity(data)) {
3373 data = this.em?.getComparator().prepareEntity(data as Entity) ?? serialize(data as Entity);
3374 }
3375
3376 this.#state.data = this.helper.processData(data, this.#state.flags.has(QueryFlag.CONVERT_CUSTOM_TYPES), false);
3377 }
3378
3379 if (cond) {
3380 this.where(cond);
3381 }
3382
3383 return this;
3384 }
3385
3386 private getQueryBase(processVirtualEntity: boolean): NativeQueryBuilder {
3387 const qb = this.platform.createNativeQueryBuilder().setFlags(this.#state.flags);

Callers 6

selectMethod · 0.95
insertMethod · 0.95
updateMethod · 0.95
deleteMethod · 0.95
truncateMethod · 0.95
countMethod · 0.95

Calls 10

ensureNotFinalizedMethod · 0.95
whereMethod · 0.95
serializeFunction · 0.90
hasObjectKeysMethod · 0.80
prepareEntityMethod · 0.80
processDataMethod · 0.80
hasMethod · 0.65
isEntityMethod · 0.45
getComparatorMethod · 0.45

Tested by

no test coverage detected