@mikro-orm/knex 6.0.0-dev.28 → 6.0.0-dev.280

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/AbstractSqlConnection.d.ts +22 -4
  2. package/AbstractSqlConnection.js +48 -18
  3. package/AbstractSqlDriver.d.ts +30 -24
  4. package/AbstractSqlDriver.js +592 -274
  5. package/AbstractSqlPlatform.d.ts +9 -4
  6. package/AbstractSqlPlatform.js +40 -5
  7. package/MonkeyPatchable.d.ts +1 -0
  8. package/MonkeyPatchable.js +3 -0
  9. package/PivotCollectionPersister.d.ts +17 -0
  10. package/PivotCollectionPersister.js +128 -0
  11. package/README.md +64 -107
  12. package/SqlEntityManager.d.ts +4 -8
  13. package/SqlEntityManager.js +8 -12
  14. package/SqlEntityRepository.d.ts +7 -6
  15. package/SqlEntityRepository.js +11 -8
  16. package/index.mjs +22 -3
  17. package/package.json +8 -8
  18. package/query/ArrayCriteriaNode.d.ts +3 -2
  19. package/query/ArrayCriteriaNode.js +7 -2
  20. package/query/CriteriaNode.d.ts +6 -4
  21. package/query/CriteriaNode.js +22 -9
  22. package/query/CriteriaNodeFactory.d.ts +1 -1
  23. package/query/CriteriaNodeFactory.js +27 -11
  24. package/query/ObjectCriteriaNode.d.ts +3 -2
  25. package/query/ObjectCriteriaNode.js +72 -28
  26. package/query/QueryBuilder.d.ts +58 -26
  27. package/query/QueryBuilder.js +438 -142
  28. package/query/QueryBuilderHelper.d.ts +13 -18
  29. package/query/QueryBuilderHelper.js +190 -163
  30. package/query/ScalarCriteriaNode.d.ts +3 -2
  31. package/query/ScalarCriteriaNode.js +14 -4
  32. package/query/enums.d.ts +7 -0
  33. package/query/enums.js +10 -2
  34. package/schema/DatabaseSchema.d.ts +5 -2
  35. package/schema/DatabaseSchema.js +26 -8
  36. package/schema/DatabaseTable.d.ts +12 -4
  37. package/schema/DatabaseTable.js +369 -44
  38. package/schema/SchemaComparator.d.ts +7 -5
  39. package/schema/SchemaComparator.js +68 -35
  40. package/schema/SchemaHelper.d.ts +7 -5
  41. package/schema/SchemaHelper.js +25 -11
  42. package/schema/SqlSchemaGenerator.d.ts +3 -4
  43. package/schema/SqlSchemaGenerator.js +71 -28
  44. package/typings.d.ts +27 -8
@@ -8,33 +8,64 @@ const enums_1 = require("./enums");
8
8
  * @internal
9
9
  */
10
10
  class ObjectCriteriaNode extends CriteriaNode_1.CriteriaNode {
11
- process(qb, alias) {
12
- const nestedAlias = qb.getAliasForJoinPath(this.getPath());
13
- const ownerAlias = alias || qb.alias;
11
+ process(qb, options) {
12
+ const nestedAlias = qb.getAliasForJoinPath(this.getPath(), options);
13
+ const ownerAlias = options?.alias || qb.alias;
14
+ const keys = Object.keys(this.payload);
15
+ let alias = options?.alias;
14
16
  if (nestedAlias) {
15
17
  alias = nestedAlias;
16
18
  }
17
- if (this.shouldAutoJoin(nestedAlias)) {
19
+ if (this.shouldAutoJoin(qb, nestedAlias)) {
20
+ if (keys.some(k => ['$some', '$none', '$every'].includes(k))) {
21
+ const $and = [];
22
+ const primaryKeys = this.metadata.find(this.entityName).primaryKeys.map(pk => {
23
+ return [enums_1.QueryType.SELECT, enums_1.QueryType.COUNT].includes(qb.type) ? `${alias}.${pk}` : pk;
24
+ });
25
+ for (const key of keys) {
26
+ if (!['$some', '$none', '$every'].includes(key)) {
27
+ throw new Error('Mixing collection operators with other filters is not allowed.');
28
+ }
29
+ const payload = this.payload[key].unwrap();
30
+ const sub = qb.clone(true).innerJoin(this.key, qb.getNextAlias(this.prop.type));
31
+ sub.select(this.prop.targetMeta.primaryKeys);
32
+ if (key === '$every') {
33
+ sub.where({ $not: { [this.key]: payload } });
34
+ }
35
+ else {
36
+ sub.where({ [this.key]: payload });
37
+ }
38
+ const op = key === '$some' ? '$in' : '$nin';
39
+ $and.push({
40
+ [core_1.Utils.getPrimaryKeyHash(primaryKeys)]: { [op]: sub.getKnexQuery() },
41
+ });
42
+ }
43
+ return { $and };
44
+ }
18
45
  alias = this.autoJoin(qb, ownerAlias);
19
46
  }
20
- return Object.keys(this.payload).reduce((o, field) => {
47
+ return keys.reduce((o, field) => {
21
48
  const childNode = this.payload[field];
22
- const payload = childNode.process(qb, this.prop ? alias : ownerAlias);
49
+ const payload = childNode.process(qb, { ...options, alias: this.prop ? alias : ownerAlias });
23
50
  const operator = core_1.Utils.isOperator(field);
24
- const customExpression = ObjectCriteriaNode.isCustomExpression(field);
51
+ const isRawField = core_1.RawQueryFragment.isKnownFragment(field);
25
52
  // we need to keep the prefixing for formulas otherwise we would lose aliasing context when nesting inside group operators
26
53
  const virtual = childNode.prop?.persist === false && !childNode.prop?.formula;
27
54
  // if key is missing, we are inside group operator and we need to prefix with alias
28
55
  const primaryKey = this.key && this.metadata.find(this.entityName).primaryKeys.includes(field);
29
56
  if (childNode.shouldInline(payload)) {
30
- const childAlias = qb.getAliasForJoinPath(childNode.getPath());
57
+ const childAlias = qb.getAliasForJoinPath(childNode.getPath(), options);
31
58
  this.inlineChildPayload(o, payload, field, alias, childAlias);
32
59
  }
33
60
  else if (childNode.shouldRename(payload)) {
34
61
  o[childNode.renameFieldToPK(qb)] = payload;
35
62
  }
36
- else if (primaryKey || virtual || operator || customExpression || field.includes('.') || ![enums_1.QueryType.SELECT, enums_1.QueryType.COUNT].includes(qb.type ?? enums_1.QueryType.SELECT)) {
37
- o[field.replace(/\[::alias::]/g, alias)] = payload;
63
+ else if (isRawField) {
64
+ const rawField = core_1.RawQueryFragment.getKnownFragment(field);
65
+ o[(0, core_1.raw)(rawField.sql.replaceAll(core_1.ALIAS_REPLACEMENT, alias), rawField.params)] = payload;
66
+ }
67
+ else if (primaryKey || virtual || operator || field.includes('.') || ![enums_1.QueryType.SELECT, enums_1.QueryType.COUNT].includes(qb.type ?? enums_1.QueryType.SELECT)) {
68
+ o[field.replaceAll(core_1.ALIAS_REPLACEMENT, alias)] = payload;
38
69
  }
39
70
  else {
40
71
  o[`${alias}.${field}`] = payload;
@@ -42,22 +73,29 @@ class ObjectCriteriaNode extends CriteriaNode_1.CriteriaNode {
42
73
  return o;
43
74
  }, {});
44
75
  }
76
+ unwrap() {
77
+ return Object.keys(this.payload).reduce((o, field) => {
78
+ o[field] = this.payload[field].unwrap();
79
+ return o;
80
+ }, {});
81
+ }
45
82
  willAutoJoin(qb, alias) {
46
83
  const nestedAlias = qb.getAliasForJoinPath(this.getPath());
47
84
  const ownerAlias = alias || qb.alias;
85
+ const keys = Object.keys(this.payload);
48
86
  if (nestedAlias) {
49
87
  alias = nestedAlias;
50
88
  }
51
- if (this.shouldAutoJoin(nestedAlias)) {
52
- return true;
89
+ if (this.shouldAutoJoin(qb, nestedAlias)) {
90
+ return !keys.some(k => ['$some', '$none', '$every'].includes(k));
53
91
  }
54
- return Object.keys(this.payload).some(field => {
92
+ return keys.some(field => {
55
93
  const childNode = this.payload[field];
56
94
  return childNode.willAutoJoin(qb, this.prop ? alias : ownerAlias);
57
95
  });
58
96
  }
59
97
  shouldInline(payload) {
60
- const customExpression = ObjectCriteriaNode.isCustomExpression(this.key);
98
+ const customExpression = core_1.RawQueryFragment.isKnownFragment(this.key);
61
99
  const scalar = core_1.Utils.isPrimaryKey(payload) || payload instanceof RegExp || payload instanceof Date || customExpression;
62
100
  const operator = core_1.Utils.isObject(payload) && Object.keys(payload).every(k => core_1.Utils.isOperator(k, false));
63
101
  return !!this.prop && this.prop.kind !== core_1.ReferenceKind.SCALAR && !scalar && !operator;
@@ -68,11 +106,11 @@ class ObjectCriteriaNode extends CriteriaNode_1.CriteriaNode {
68
106
  if (core_1.Utils.isOperator(k, false)) {
69
107
  const tmp = payload[k];
70
108
  delete payload[k];
71
- o[`${alias}.${field}`] = { [k]: tmp, ...(o[`${alias}.${field}`] || {}) };
109
+ o[this.aliased(field, alias)] = { [k]: tmp, ...(o[this.aliased(field, alias)] || {}) };
72
110
  }
73
111
  else if (this.isPrefixed(k) || core_1.Utils.isOperator(k) || !childAlias) {
74
112
  const idx = prop.referencedPKs.indexOf(k);
75
- const key = idx !== -1 && !childAlias ? prop.joinColumns[idx] : k;
113
+ const key = idx !== -1 && !childAlias && ![core_1.ReferenceKind.ONE_TO_MANY, core_1.ReferenceKind.MANY_TO_MANY].includes(prop.kind) ? prop.joinColumns[idx] : k;
76
114
  if (key in o) {
77
115
  const $and = o.$and ?? [];
78
116
  $and.push({ [key]: o[key] }, { [key]: payload[k] });
@@ -81,9 +119,7 @@ class ObjectCriteriaNode extends CriteriaNode_1.CriteriaNode {
81
119
  }
82
120
  else if (core_1.Utils.isOperator(k) && Array.isArray(payload[k])) {
83
121
  o[key] = payload[k].map((child) => Object.keys(child).reduce((o, childKey) => {
84
- const key = (this.isPrefixed(childKey) || core_1.Utils.isOperator(childKey))
85
- ? childKey
86
- : `${childAlias}.${childKey}`;
122
+ const key = (this.isPrefixed(childKey) || core_1.Utils.isOperator(childKey)) ? childKey : this.aliased(childKey, childAlias);
87
123
  o[key] = child[childKey];
88
124
  return o;
89
125
  }, {}));
@@ -92,23 +128,28 @@ class ObjectCriteriaNode extends CriteriaNode_1.CriteriaNode {
92
128
  o[key] = payload[k];
93
129
  }
94
130
  }
95
- else if (ObjectCriteriaNode.isCustomExpression(k)) {
131
+ else if (core_1.RawQueryFragment.isKnownFragment(k)) {
96
132
  o[k] = payload[k];
97
133
  }
98
134
  else {
99
135
  o[`${childAlias}.${k}`] = payload[k];
136
+ o[this.aliased(k, childAlias)] = payload[k];
100
137
  }
101
138
  }
102
139
  }
103
- shouldAutoJoin(nestedAlias) {
140
+ shouldAutoJoin(qb, nestedAlias) {
104
141
  if (!this.prop || !this.parent) {
105
142
  return false;
106
143
  }
144
+ const keys = Object.keys(this.payload);
145
+ if (keys.every(k => k.includes('.') && k.startsWith(`${qb.alias}.`))) {
146
+ return false;
147
+ }
148
+ const meta = this.metadata.find(this.entityName);
107
149
  const embeddable = this.prop.kind === core_1.ReferenceKind.EMBEDDED;
108
150
  const knownKey = [core_1.ReferenceKind.SCALAR, core_1.ReferenceKind.MANY_TO_ONE, core_1.ReferenceKind.EMBEDDED].includes(this.prop.kind) || (this.prop.kind === core_1.ReferenceKind.ONE_TO_ONE && this.prop.owner);
109
- const operatorKeys = knownKey && Object.keys(this.payload).every(key => core_1.Utils.isOperator(key, false));
110
- const primaryKeys = knownKey && Object.keys(this.payload).every(key => {
111
- const meta = this.metadata.find(this.entityName);
151
+ const operatorKeys = knownKey && keys.every(key => core_1.Utils.isOperator(key, false));
152
+ const primaryKeys = knownKey && keys.every(key => {
112
153
  if (!meta.primaryKeys.includes(key)) {
113
154
  return false;
114
155
  }
@@ -121,17 +162,20 @@ class ObjectCriteriaNode extends CriteriaNode_1.CriteriaNode {
121
162
  }
122
163
  autoJoin(qb, alias) {
123
164
  const nestedAlias = qb.getNextAlias(this.prop?.pivotTable ?? this.entityName);
124
- const customExpression = ObjectCriteriaNode.isCustomExpression(this.key);
165
+ const customExpression = core_1.RawQueryFragment.isKnownFragment(this.key);
125
166
  const scalar = core_1.Utils.isPrimaryKey(this.payload) || this.payload instanceof RegExp || this.payload instanceof Date || customExpression;
126
167
  const operator = core_1.Utils.isPlainObject(this.payload) && Object.keys(this.payload).every(k => core_1.Utils.isOperator(k, false));
127
168
  const field = `${alias}.${this.prop.name}`;
169
+ const method = qb.hasFlag(core_1.QueryFlag.INFER_POPULATE) ? 'joinAndSelect' : 'join';
128
170
  if (this.prop.kind === core_1.ReferenceKind.MANY_TO_MANY && (scalar || operator)) {
129
- qb.join(field, nestedAlias, undefined, 'pivotJoin', this.getPath());
171
+ qb.join(field, nestedAlias, undefined, enums_1.JoinType.pivotJoin, this.getPath());
130
172
  }
131
173
  else {
132
174
  const prev = qb._fields?.slice();
133
- qb.join(field, nestedAlias, undefined, 'leftJoin', this.getPath());
134
- qb._fields = prev;
175
+ qb[method](field, nestedAlias, undefined, enums_1.JoinType.leftJoin, this.getPath());
176
+ if (!qb.hasFlag(core_1.QueryFlag.INFER_POPULATE)) {
177
+ qb._fields = prev;
178
+ }
135
179
  }
136
180
  return nestedAlias;
137
181
  }
@@ -1,14 +1,17 @@
1
1
  /// <reference types="node" />
2
2
  import { inspect } from 'util';
3
3
  import type { Knex } from 'knex';
4
- import type { AnyEntity, ConnectionType, Dictionary, EntityData, EntityName, EntityProperty, FlushMode, GroupOperator, MetadataStorage, ObjectQuery, PopulateOptions, QBFilterQuery, QBQueryOrderMap, QueryResult, RequiredEntityData } from '@mikro-orm/core';
5
- import { LockMode, PopulateHint, QueryFlag } from '@mikro-orm/core';
6
- import { QueryType } from './enums';
4
+ import { type AnyEntity, type ConnectionType, type Dictionary, type EntityData, type EntityName, type EntityProperty, type FlushMode, type GroupOperator, LockMode, type LoggingOptions, type MetadataStorage, type ObjectQuery, PopulateHint, type PopulateOptions, type QBFilterQuery, type QBQueryOrderMap, QueryFlag, type QueryResult, type RequiredEntityData } from '@mikro-orm/core';
5
+ import { QueryType, JoinType } from './enums';
7
6
  import type { AbstractSqlDriver } from '../AbstractSqlDriver';
8
- import { QueryBuilderHelper } from './QueryBuilderHelper';
9
- import type { Alias } from './QueryBuilderHelper';
7
+ import { type Alias, QueryBuilderHelper } from './QueryBuilderHelper';
10
8
  import type { SqlEntityManager } from '../SqlEntityManager';
11
- import type { Field } from '../typings';
9
+ import type { Field, ICriteriaNodeProcessOptions, JoinOptions } from '../typings';
10
+ import type { AbstractSqlPlatform } from '../AbstractSqlPlatform';
11
+ export interface ExecuteOptions {
12
+ mapResults?: boolean;
13
+ mergeResults?: boolean;
14
+ }
12
15
  /**
13
16
  * SQL query builder with fluent interface.
14
17
  *
@@ -29,12 +32,14 @@ import type { Field } from '../typings';
29
32
  * ```
30
33
  */
31
34
  export declare class QueryBuilder<T extends object = AnyEntity> {
35
+ #private;
32
36
  private readonly metadata;
33
37
  private readonly driver;
34
38
  private readonly context?;
35
39
  private connectionType?;
36
40
  private readonly em?;
37
- get mainAlias(): Alias;
41
+ private readonly loggerContext?;
42
+ get mainAlias(): Alias<T>;
38
43
  get alias(): string;
39
44
  get helper(): QueryBuilderHelper;
40
45
  /** @internal */
@@ -44,7 +49,9 @@ export declare class QueryBuilder<T extends object = AnyEntity> {
44
49
  /** @internal */
45
50
  _populate: PopulateOptions<T>[];
46
51
  /** @internal */
47
- _populateWhere?: ObjectQuery<T> | PopulateHint;
52
+ _populateWhere?: ObjectQuery<T> | PopulateHint | `${PopulateHint}`;
53
+ /** @internal */
54
+ __populateWhere?: ObjectQuery<T> | PopulateHint | `${PopulateHint}`;
48
55
  /** @internal */
49
56
  _populateMap: Dictionary<string>;
50
57
  private aliasCounter;
@@ -58,6 +65,7 @@ export declare class QueryBuilder<T extends object = AnyEntity> {
58
65
  private _orderBy;
59
66
  private _groupBy;
60
67
  private _having;
68
+ private _returning?;
61
69
  private _onConflict?;
62
70
  private _limit?;
63
71
  private _offset?;
@@ -65,6 +73,8 @@ export declare class QueryBuilder<T extends object = AnyEntity> {
65
73
  private _joinedProps;
66
74
  private _cache?;
67
75
  private _indexHint?;
76
+ private _comments;
77
+ private _hintComments;
68
78
  private flushMode?;
69
79
  private lockMode?;
70
80
  private lockTables?;
@@ -77,7 +87,7 @@ export declare class QueryBuilder<T extends object = AnyEntity> {
77
87
  /**
78
88
  * @internal
79
89
  */
80
- constructor(entityName: EntityName<T> | QueryBuilder<T>, metadata: MetadataStorage, driver: AbstractSqlDriver, context?: Knex.Transaction<any, any[]> | undefined, alias?: string, connectionType?: ConnectionType | undefined, em?: SqlEntityManager<AbstractSqlDriver<import("../AbstractSqlConnection").AbstractSqlConnection, import("../AbstractSqlPlatform").AbstractSqlPlatform>> | undefined);
90
+ constructor(entityName: EntityName<T> | QueryBuilder<T>, metadata: MetadataStorage, driver: AbstractSqlDriver, context?: Knex.Transaction<any, any[]> | undefined, alias?: string, connectionType?: ConnectionType | undefined, em?: SqlEntityManager<AbstractSqlDriver<import("..").AbstractSqlConnection, AbstractSqlPlatform>> | undefined, loggerContext?: LoggingOptions | undefined);
81
91
  select(fields: Field<T> | Field<T>[], distinct?: boolean): SelectQueryBuilder<T>;
82
92
  addSelect(fields: Field<T> | Field<T>[]): SelectQueryBuilder<T>;
83
93
  distinct(): SelectQueryBuilder<T>;
@@ -88,11 +98,17 @@ export declare class QueryBuilder<T extends object = AnyEntity> {
88
98
  delete(cond?: QBFilterQuery): DeleteQueryBuilder<T>;
89
99
  truncate(): TruncateQueryBuilder<T>;
90
100
  count(field?: string | string[], distinct?: boolean): CountQueryBuilder<T>;
91
- join(field: string, alias: string, cond?: QBFilterQuery, type?: 'leftJoin' | 'innerJoin' | 'pivotJoin', path?: string): this;
92
- leftJoin(field: string, alias: string, cond?: QBFilterQuery): this;
93
- joinAndSelect(field: string, alias: string, cond?: QBFilterQuery, type?: 'leftJoin' | 'innerJoin' | 'pivotJoin', path?: string): SelectQueryBuilder<T>;
94
- leftJoinAndSelect(field: string, alias: string, cond?: QBFilterQuery): SelectQueryBuilder<T>;
95
- protected getFieldsForJoinedLoad(prop: EntityProperty<T>, alias: string): Field<T>[];
101
+ join(field: string | Knex.QueryBuilder | QueryBuilder<any>, alias: string, cond?: QBFilterQuery, type?: JoinType, path?: string, schema?: string): this;
102
+ innerJoin(field: string | Knex.QueryBuilder | QueryBuilder<any>, alias: string, cond?: QBFilterQuery, schema?: string): this;
103
+ innerJoinLateral(field: string | Knex.QueryBuilder | QueryBuilder<any>, alias: string, cond?: QBFilterQuery, schema?: string): this;
104
+ leftJoin(field: string | Knex.QueryBuilder | QueryBuilder<any>, alias: string, cond?: QBFilterQuery, schema?: string): this;
105
+ leftJoinLateral(field: string | Knex.QueryBuilder | QueryBuilder<any>, alias: string, cond?: QBFilterQuery, schema?: string): this;
106
+ joinAndSelect(field: string | [field: string, qb: Knex.QueryBuilder | QueryBuilder<any>], alias: string, cond?: QBFilterQuery, type?: JoinType, path?: string, fields?: string[], schema?: string): SelectQueryBuilder<T>;
107
+ leftJoinAndSelect(field: string | [field: string, qb: Knex.QueryBuilder | QueryBuilder<any>], alias: string, cond?: QBFilterQuery, fields?: string[], schema?: string): SelectQueryBuilder<T>;
108
+ leftJoinLateralAndSelect(field: string | [field: string, qb: Knex.QueryBuilder | QueryBuilder<any>], alias: string, cond?: QBFilterQuery, fields?: string[], schema?: string): SelectQueryBuilder<T>;
109
+ innerJoinAndSelect(field: string | [field: string, qb: Knex.QueryBuilder | QueryBuilder<any>], alias: string, cond?: QBFilterQuery, fields?: string[], schema?: string): SelectQueryBuilder<T>;
110
+ innerJoinLateralAndSelect(field: string | [field: string, qb: Knex.QueryBuilder | QueryBuilder<any>], alias: string, cond?: QBFilterQuery, fields?: string[], schema?: string): SelectQueryBuilder<T>;
111
+ protected getFieldsForJoinedLoad(prop: EntityProperty<T>, alias: string, explicitFields?: string[]): Field<T>[];
96
112
  withSubQuery(subQuery: Knex.QueryBuilder, alias: string): this;
97
113
  where(cond: QBFilterQuery<T>, operator?: keyof typeof GroupOperator): this;
98
114
  where(cond: string, params?: any[], operator?: keyof typeof GroupOperator): this;
@@ -106,17 +122,11 @@ export declare class QueryBuilder<T extends object = AnyEntity> {
106
122
  onConflict(fields?: Field<T> | Field<T>[]): this;
107
123
  ignore(): this;
108
124
  merge(data?: EntityData<T> | Field<T>[]): this;
125
+ returning(fields?: Field<T> | Field<T>[]): this;
109
126
  /**
110
127
  * @internal
111
128
  */
112
- populate(populate: PopulateOptions<T>[], populateWhere?: ObjectQuery<T> | PopulateHint): this;
113
- /**
114
- * @internal
115
- */
116
- ref(field: string): Knex.Ref<string, {
117
- [x: string]: string;
118
- }>;
119
- raw<R = Knex.Raw>(sql: string, bindings?: Knex.RawBinding[] | Knex.ValueDict): R;
129
+ populate(populate: PopulateOptions<T>[], populateWhere?: ObjectQuery<T> | PopulateHint | `${PopulateHint}`): this;
120
130
  limit(limit?: number, offset?: number): this;
121
131
  offset(offset?: number): this;
122
132
  withSchema(schema?: string): this;
@@ -124,11 +134,22 @@ export declare class QueryBuilder<T extends object = AnyEntity> {
124
134
  setFlushMode(flushMode?: FlushMode): this;
125
135
  setFlag(flag: QueryFlag): this;
126
136
  unsetFlag(flag: QueryFlag): this;
137
+ hasFlag(flag: QueryFlag): boolean;
127
138
  cache(config?: boolean | number | [string, number]): this;
128
139
  /**
129
140
  * Adds index hint to the FROM clause.
130
141
  */
131
142
  indexHint(sql: string): this;
143
+ /**
144
+ * Prepend comment to the sql query using the syntax `/* ... *&#8205;/`. Some characters are forbidden such as `/*, *&#8205;/` and `?`.
145
+ */
146
+ comment(comment: string | string[]): this;
147
+ /**
148
+ * Add hints to the query using comment-like syntax `/*+ ... *&#8205;/`. MySQL and Oracle use this syntax for optimizer hints.
149
+ * Also various DB proxies and routers use this syntax to pass hints to alter their behavior. In other dialects the hints
150
+ * are ignored as simple comments.
151
+ */
152
+ hintComment(comment: string | string[]): this;
132
153
  /**
133
154
  * Specifies FROM which entity's table select/update/delete will be executed, removing all previously set FROM-s.
134
155
  * Allows setting a main string alias of the selection data.
@@ -140,6 +161,11 @@ export declare class QueryBuilder<T extends object = AnyEntity> {
140
161
  * Returns the query with parameters as wildcards.
141
162
  */
142
163
  getQuery(): string;
164
+ toQuery(): {
165
+ sql: string;
166
+ _sql: Knex.Sql;
167
+ params: readonly unknown[];
168
+ };
143
169
  /**
144
170
  * Returns the list of all parameters for this query.
145
171
  */
@@ -151,7 +177,11 @@ export declare class QueryBuilder<T extends object = AnyEntity> {
151
177
  /**
152
178
  * @internal
153
179
  */
154
- getAliasForJoinPath(path?: string): string | undefined;
180
+ getAliasForJoinPath(path?: string | JoinOptions, options?: ICriteriaNodeProcessOptions): string | undefined;
181
+ /**
182
+ * @internal
183
+ */
184
+ getJoinForPath(path: string, options?: ICriteriaNodeProcessOptions): JoinOptions | undefined;
155
185
  /**
156
186
  * @internal
157
187
  */
@@ -164,7 +194,7 @@ export declare class QueryBuilder<T extends object = AnyEntity> {
164
194
  * Executes this QB and returns the raw results, mapped to the property names (unless disabled via last parameter).
165
195
  * Use `method` to specify what kind of result you want to get (array/single/meta).
166
196
  */
167
- execute<U = any>(method?: 'all' | 'get' | 'run', mapResults?: boolean): Promise<U>;
197
+ execute<U = any>(method?: 'all' | 'get' | 'run', options?: ExecuteOptions | boolean): Promise<U>;
168
198
  /**
169
199
  * Alias for `qb.getResultList()`
170
200
  */
@@ -194,17 +224,18 @@ export declare class QueryBuilder<T extends object = AnyEntity> {
194
224
  * You can provide `EntityName.propName` as alias, then the field name will be used based on the metadata
195
225
  */
196
226
  as(alias: string): Knex.QueryBuilder;
197
- clone(): QueryBuilder<T>;
227
+ clone(reset?: boolean): QueryBuilder<T>;
198
228
  getKnex(): Knex.QueryBuilder;
199
229
  private joinReference;
200
230
  private prepareFields;
201
231
  private init;
202
232
  private getQueryBase;
233
+ private applyDiscriminatorCondition;
203
234
  private finalize;
235
+ private processPopulateWhere;
204
236
  private hasToManyJoins;
205
237
  private wrapPaginateSubQuery;
206
238
  private wrapModifySubQuery;
207
- private autoJoinPivotTable;
208
239
  private getSchema;
209
240
  private createAlias;
210
241
  private createMainAlias;
@@ -213,6 +244,7 @@ export declare class QueryBuilder<T extends object = AnyEntity> {
213
244
  private createQueryBuilderHelper;
214
245
  private ensureFromClause;
215
246
  private ensureNotFinalized;
247
+ /** @ignore */
216
248
  [inspect.custom](depth: number): string;
217
249
  }
218
250
  export interface RunQueryBuilder<T extends object> extends Omit<QueryBuilder<T>, 'getResult' | 'getSingleResult' | 'getResultList' | 'where'> {