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