@yandjin-mikro-orm/knex 6.1.4-rc-sti-changes-1
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 +58 -0
- package/AbstractSqlConnection.js +206 -0
- package/AbstractSqlDriver.d.ts +73 -0
- package/AbstractSqlDriver.js +1378 -0
- package/AbstractSqlPlatform.d.ts +25 -0
- package/AbstractSqlPlatform.js +86 -0
- package/LICENSE +21 -0
- package/MonkeyPatchable.d.ts +11 -0
- package/MonkeyPatchable.js +39 -0
- package/PivotCollectionPersister.d.ts +17 -0
- package/PivotCollectionPersister.js +131 -0
- package/README.md +383 -0
- package/SqlEntityManager.d.ts +25 -0
- package/SqlEntityManager.js +40 -0
- package/SqlEntityRepository.d.ts +24 -0
- package/SqlEntityRepository.js +36 -0
- package/index.d.ts +18 -0
- package/index.js +40 -0
- package/index.mjs +215 -0
- package/package.json +71 -0
- package/query/ArrayCriteriaNode.d.ts +10 -0
- package/query/ArrayCriteriaNode.js +25 -0
- package/query/CriteriaNode.d.ts +31 -0
- package/query/CriteriaNode.js +147 -0
- package/query/CriteriaNodeFactory.d.ts +12 -0
- package/query/CriteriaNodeFactory.js +90 -0
- package/query/ObjectCriteriaNode.d.ts +15 -0
- package/query/ObjectCriteriaNode.js +233 -0
- package/query/QueryBuilder.d.ts +291 -0
- package/query/QueryBuilder.js +1445 -0
- package/query/QueryBuilderHelper.d.ts +64 -0
- package/query/QueryBuilderHelper.js +747 -0
- package/query/ScalarCriteriaNode.d.ts +10 -0
- package/query/ScalarCriteriaNode.js +56 -0
- package/query/enums.d.ts +15 -0
- package/query/enums.js +20 -0
- package/query/index.d.ts +8 -0
- package/query/index.js +24 -0
- package/schema/DatabaseSchema.d.ts +29 -0
- package/schema/DatabaseSchema.js +140 -0
- package/schema/DatabaseTable.d.ts +61 -0
- package/schema/DatabaseTable.js +727 -0
- package/schema/SchemaComparator.d.ts +59 -0
- package/schema/SchemaComparator.js +603 -0
- package/schema/SchemaHelper.d.ts +56 -0
- package/schema/SchemaHelper.js +274 -0
- package/schema/SqlSchemaGenerator.d.ts +63 -0
- package/schema/SqlSchemaGenerator.js +598 -0
- package/schema/index.d.ts +5 -0
- package/schema/index.js +21 -0
- package/typings.d.ts +174 -0
- package/typings.js +2 -0
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ObjectCriteriaNode = void 0;
|
|
4
|
+
const core_1 = require("@yandjin-mikro-orm/core");
|
|
5
|
+
const CriteriaNode_1 = require("./CriteriaNode");
|
|
6
|
+
const enums_1 = require("./enums");
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
class ObjectCriteriaNode extends CriteriaNode_1.CriteriaNode {
|
|
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;
|
|
16
|
+
if (nestedAlias) {
|
|
17
|
+
alias = nestedAlias;
|
|
18
|
+
}
|
|
19
|
+
if (this.shouldAutoJoin(qb, nestedAlias)) {
|
|
20
|
+
if (keys.some((k) => ["$some", "$none", "$every"].includes(k))) {
|
|
21
|
+
const $and = [];
|
|
22
|
+
const primaryKeys = this.metadata
|
|
23
|
+
.find(this.entityName)
|
|
24
|
+
.primaryKeys.map((pk) => {
|
|
25
|
+
return [enums_1.QueryType.SELECT, enums_1.QueryType.COUNT].includes(qb.type)
|
|
26
|
+
? `${alias}.${pk}`
|
|
27
|
+
: pk;
|
|
28
|
+
});
|
|
29
|
+
for (const key of keys) {
|
|
30
|
+
if (!["$some", "$none", "$every"].includes(key)) {
|
|
31
|
+
throw new Error("Mixing collection operators with other filters is not allowed.");
|
|
32
|
+
}
|
|
33
|
+
const payload = this.payload[key].unwrap();
|
|
34
|
+
const sub = qb
|
|
35
|
+
.clone(true)
|
|
36
|
+
.from(this.parent.entityName)
|
|
37
|
+
.innerJoin(this.key, qb.getNextAlias(this.prop.type))
|
|
38
|
+
.select(this.prop.targetMeta.primaryKeys);
|
|
39
|
+
if (key === "$every") {
|
|
40
|
+
sub.where({ $not: { [this.key]: payload } });
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
sub.where({ [this.key]: payload });
|
|
44
|
+
}
|
|
45
|
+
const op = key === "$some" ? "$in" : "$nin";
|
|
46
|
+
$and.push({
|
|
47
|
+
[core_1.Utils.getPrimaryKeyHash(primaryKeys)]: {
|
|
48
|
+
[op]: sub.getKnexQuery(),
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return { $and };
|
|
53
|
+
}
|
|
54
|
+
alias = this.autoJoin(qb, ownerAlias);
|
|
55
|
+
}
|
|
56
|
+
return keys.reduce((o, field) => {
|
|
57
|
+
const childNode = this.payload[field];
|
|
58
|
+
const payload = childNode.process(qb, {
|
|
59
|
+
...options,
|
|
60
|
+
alias: this.prop ? alias : ownerAlias,
|
|
61
|
+
});
|
|
62
|
+
const operator = core_1.Utils.isOperator(field);
|
|
63
|
+
const isRawField = core_1.RawQueryFragment.isKnownFragment(field);
|
|
64
|
+
// we need to keep the prefixing for formulas otherwise we would lose aliasing context when nesting inside group operators
|
|
65
|
+
const virtual = childNode.prop?.persist === false && !childNode.prop?.formula;
|
|
66
|
+
// if key is missing, we are inside group operator and we need to prefix with alias
|
|
67
|
+
const primaryKey = this.key &&
|
|
68
|
+
this.metadata.find(this.entityName).primaryKeys.includes(field);
|
|
69
|
+
if (childNode.shouldInline(payload)) {
|
|
70
|
+
const childAlias = qb.getAliasForJoinPath(childNode.getPath(), options);
|
|
71
|
+
this.inlineChildPayload(o, payload, field, alias, childAlias);
|
|
72
|
+
}
|
|
73
|
+
else if (childNode.shouldRename(payload)) {
|
|
74
|
+
o[childNode.renameFieldToPK(qb)] = payload;
|
|
75
|
+
}
|
|
76
|
+
else if (isRawField) {
|
|
77
|
+
const rawField = core_1.RawQueryFragment.getKnownFragment(field);
|
|
78
|
+
o[(0, core_1.raw)(rawField.sql.replaceAll(core_1.ALIAS_REPLACEMENT, alias), rawField.params)] = payload;
|
|
79
|
+
}
|
|
80
|
+
else if (primaryKey ||
|
|
81
|
+
virtual ||
|
|
82
|
+
operator ||
|
|
83
|
+
field.includes(".") ||
|
|
84
|
+
![enums_1.QueryType.SELECT, enums_1.QueryType.COUNT].includes(qb.type ?? enums_1.QueryType.SELECT)) {
|
|
85
|
+
o[field.replaceAll(core_1.ALIAS_REPLACEMENT, alias)] = payload;
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
o[`${alias}.${field}`] = payload;
|
|
89
|
+
}
|
|
90
|
+
return o;
|
|
91
|
+
}, {});
|
|
92
|
+
}
|
|
93
|
+
unwrap() {
|
|
94
|
+
return Object.keys(this.payload).reduce((o, field) => {
|
|
95
|
+
o[field] = this.payload[field].unwrap();
|
|
96
|
+
return o;
|
|
97
|
+
}, {});
|
|
98
|
+
}
|
|
99
|
+
willAutoJoin(qb, alias) {
|
|
100
|
+
const nestedAlias = qb.getAliasForJoinPath(this.getPath());
|
|
101
|
+
const ownerAlias = alias || qb.alias;
|
|
102
|
+
const keys = Object.keys(this.payload);
|
|
103
|
+
if (nestedAlias) {
|
|
104
|
+
alias = nestedAlias;
|
|
105
|
+
}
|
|
106
|
+
if (this.shouldAutoJoin(qb, nestedAlias)) {
|
|
107
|
+
return !keys.some((k) => ["$some", "$none", "$every"].includes(k));
|
|
108
|
+
}
|
|
109
|
+
return keys.some((field) => {
|
|
110
|
+
const childNode = this.payload[field];
|
|
111
|
+
return childNode.willAutoJoin(qb, this.prop ? alias : ownerAlias);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
shouldInline(payload) {
|
|
115
|
+
const customExpression = core_1.RawQueryFragment.isKnownFragment(this.key);
|
|
116
|
+
const scalar = core_1.Utils.isPrimaryKey(payload) ||
|
|
117
|
+
payload instanceof RegExp ||
|
|
118
|
+
payload instanceof Date ||
|
|
119
|
+
customExpression;
|
|
120
|
+
const operator = core_1.Utils.isObject(payload) &&
|
|
121
|
+
Object.keys(payload).every((k) => core_1.Utils.isOperator(k, false));
|
|
122
|
+
return (!!this.prop &&
|
|
123
|
+
this.prop.kind !== core_1.ReferenceKind.SCALAR &&
|
|
124
|
+
!scalar &&
|
|
125
|
+
!operator);
|
|
126
|
+
}
|
|
127
|
+
inlineChildPayload(o, payload, field, alias, childAlias) {
|
|
128
|
+
const prop = this.metadata.find(this.entityName).properties[field];
|
|
129
|
+
for (const k of Object.keys(payload)) {
|
|
130
|
+
if (core_1.Utils.isOperator(k, false)) {
|
|
131
|
+
const tmp = payload[k];
|
|
132
|
+
delete payload[k];
|
|
133
|
+
o[this.aliased(field, alias)] = {
|
|
134
|
+
[k]: tmp,
|
|
135
|
+
...(o[this.aliased(field, alias)] || {}),
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
else if (this.isPrefixed(k) || core_1.Utils.isOperator(k) || !childAlias) {
|
|
139
|
+
const idx = prop.referencedPKs.indexOf(k);
|
|
140
|
+
const key = idx !== -1 &&
|
|
141
|
+
!childAlias &&
|
|
142
|
+
![core_1.ReferenceKind.ONE_TO_MANY, core_1.ReferenceKind.MANY_TO_MANY].includes(prop.kind)
|
|
143
|
+
? prop.joinColumns[idx]
|
|
144
|
+
: k;
|
|
145
|
+
if (key in o) {
|
|
146
|
+
const $and = o.$and ?? [];
|
|
147
|
+
$and.push({ [key]: o[key] }, { [key]: payload[k] });
|
|
148
|
+
delete o[key];
|
|
149
|
+
o.$and = $and;
|
|
150
|
+
}
|
|
151
|
+
else if (core_1.Utils.isOperator(k) && Array.isArray(payload[k])) {
|
|
152
|
+
o[key] = payload[k].map((child) => Object.keys(child).reduce((o, childKey) => {
|
|
153
|
+
const key = this.isPrefixed(childKey) || core_1.Utils.isOperator(childKey)
|
|
154
|
+
? childKey
|
|
155
|
+
: this.aliased(childKey, childAlias);
|
|
156
|
+
o[key] = child[childKey];
|
|
157
|
+
return o;
|
|
158
|
+
}, {}));
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
o[key] = payload[k];
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
else if (core_1.RawQueryFragment.isKnownFragment(k)) {
|
|
165
|
+
o[k] = payload[k];
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
o[`${childAlias}.${k}`] = payload[k];
|
|
169
|
+
o[this.aliased(k, childAlias)] = payload[k];
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
shouldAutoJoin(qb, nestedAlias) {
|
|
174
|
+
if (!this.prop || !this.parent) {
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
const keys = Object.keys(this.payload);
|
|
178
|
+
if (keys.every((k) => k.includes(".") && k.startsWith(`${qb.alias}.`))) {
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
const meta = this.metadata.find(this.entityName);
|
|
182
|
+
const embeddable = this.prop.kind === core_1.ReferenceKind.EMBEDDED;
|
|
183
|
+
const knownKey = [
|
|
184
|
+
core_1.ReferenceKind.SCALAR,
|
|
185
|
+
core_1.ReferenceKind.MANY_TO_ONE,
|
|
186
|
+
core_1.ReferenceKind.EMBEDDED,
|
|
187
|
+
].includes(this.prop.kind) ||
|
|
188
|
+
(this.prop.kind === core_1.ReferenceKind.ONE_TO_ONE && this.prop.owner);
|
|
189
|
+
const operatorKeys = knownKey && keys.every((key) => core_1.Utils.isOperator(key, false));
|
|
190
|
+
const primaryKeys = knownKey &&
|
|
191
|
+
keys.every((key) => {
|
|
192
|
+
if (!meta.primaryKeys.includes(key)) {
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
if (!core_1.Utils.isPlainObject(this.payload[key].payload) ||
|
|
196
|
+
![core_1.ReferenceKind.ONE_TO_ONE, core_1.ReferenceKind.MANY_TO_ONE].includes(meta.properties[key].kind)) {
|
|
197
|
+
return true;
|
|
198
|
+
}
|
|
199
|
+
return Object.keys(this.payload[key].payload).every((k) => meta.properties[key].targetMeta.primaryKeys.includes(k));
|
|
200
|
+
});
|
|
201
|
+
return !primaryKeys && !nestedAlias && !operatorKeys && !embeddable;
|
|
202
|
+
}
|
|
203
|
+
autoJoin(qb, alias) {
|
|
204
|
+
const nestedAlias = qb.getNextAlias(this.prop?.pivotTable ?? this.entityName);
|
|
205
|
+
const customExpression = core_1.RawQueryFragment.isKnownFragment(this.key);
|
|
206
|
+
const scalar = core_1.Utils.isPrimaryKey(this.payload) ||
|
|
207
|
+
this.payload instanceof RegExp ||
|
|
208
|
+
this.payload instanceof Date ||
|
|
209
|
+
customExpression;
|
|
210
|
+
const operator = core_1.Utils.isPlainObject(this.payload) &&
|
|
211
|
+
Object.keys(this.payload).every((k) => core_1.Utils.isOperator(k, false));
|
|
212
|
+
const field = `${alias}.${this.prop.name}`;
|
|
213
|
+
const method = qb.hasFlag(core_1.QueryFlag.INFER_POPULATE)
|
|
214
|
+
? "joinAndSelect"
|
|
215
|
+
: "join";
|
|
216
|
+
if (this.prop.kind === core_1.ReferenceKind.MANY_TO_MANY &&
|
|
217
|
+
(scalar || operator)) {
|
|
218
|
+
qb.join(field, nestedAlias, undefined, enums_1.JoinType.pivotJoin, this.getPath());
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
const prev = qb._fields?.slice();
|
|
222
|
+
qb[method](field, nestedAlias, undefined, enums_1.JoinType.leftJoin, this.getPath());
|
|
223
|
+
if (!qb.hasFlag(core_1.QueryFlag.INFER_POPULATE)) {
|
|
224
|
+
qb._fields = prev;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return nestedAlias;
|
|
228
|
+
}
|
|
229
|
+
isPrefixed(field) {
|
|
230
|
+
return !!field.match(/\w+\./);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
exports.ObjectCriteriaNode = ObjectCriteriaNode;
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { inspect } from "util";
|
|
3
|
+
import type { Knex } from "knex";
|
|
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 "@yandjin-mikro-orm/core";
|
|
5
|
+
import { JoinType, QueryType } from "./enums";
|
|
6
|
+
import type { AbstractSqlDriver } from "../AbstractSqlDriver";
|
|
7
|
+
import { type Alias, QueryBuilderHelper } from "./QueryBuilderHelper";
|
|
8
|
+
import type { SqlEntityManager } from "../SqlEntityManager";
|
|
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
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* SQL query builder with fluent interface.
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* const qb = orm.em.createQueryBuilder(Publisher);
|
|
20
|
+
* qb.select('*')
|
|
21
|
+
* .where({
|
|
22
|
+
* name: 'test 123',
|
|
23
|
+
* type: PublisherType.GLOBAL,
|
|
24
|
+
* })
|
|
25
|
+
* .orderBy({
|
|
26
|
+
* name: QueryOrder.DESC,
|
|
27
|
+
* type: QueryOrder.ASC,
|
|
28
|
+
* })
|
|
29
|
+
* .limit(2, 1);
|
|
30
|
+
*
|
|
31
|
+
* const publisher = await qb.getSingleResult();
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare class QueryBuilder<T extends object = AnyEntity> {
|
|
35
|
+
#private;
|
|
36
|
+
private readonly metadata;
|
|
37
|
+
private readonly driver;
|
|
38
|
+
private readonly context?;
|
|
39
|
+
private connectionType?;
|
|
40
|
+
private readonly em?;
|
|
41
|
+
private readonly loggerContext?;
|
|
42
|
+
get mainAlias(): Alias<T>;
|
|
43
|
+
get alias(): string;
|
|
44
|
+
get helper(): QueryBuilderHelper;
|
|
45
|
+
/** @internal */
|
|
46
|
+
type?: QueryType;
|
|
47
|
+
/** @internal */
|
|
48
|
+
_fields?: Field<T>[];
|
|
49
|
+
/** @internal */
|
|
50
|
+
_populate: PopulateOptions<T>[];
|
|
51
|
+
/** @internal */
|
|
52
|
+
_populateWhere?: ObjectQuery<T> | PopulateHint | `${PopulateHint}`;
|
|
53
|
+
/** @internal */
|
|
54
|
+
__populateWhere?: ObjectQuery<T> | PopulateHint | `${PopulateHint}`;
|
|
55
|
+
/** @internal */
|
|
56
|
+
_populateMap: Dictionary<string>;
|
|
57
|
+
/** @internal */
|
|
58
|
+
readonly rawFragments: Set<string>;
|
|
59
|
+
private aliasCounter;
|
|
60
|
+
private flags;
|
|
61
|
+
private finalized;
|
|
62
|
+
private _joins;
|
|
63
|
+
private _explicitAlias;
|
|
64
|
+
private _schema?;
|
|
65
|
+
private _cond;
|
|
66
|
+
private _data;
|
|
67
|
+
private _orderBy;
|
|
68
|
+
private _groupBy;
|
|
69
|
+
private _having;
|
|
70
|
+
private _returning?;
|
|
71
|
+
private _onConflict?;
|
|
72
|
+
private _limit?;
|
|
73
|
+
private _offset?;
|
|
74
|
+
private _distinctOn?;
|
|
75
|
+
private _joinedProps;
|
|
76
|
+
private _cache?;
|
|
77
|
+
private _indexHint?;
|
|
78
|
+
private _comments;
|
|
79
|
+
private _hintComments;
|
|
80
|
+
private flushMode?;
|
|
81
|
+
private lockMode?;
|
|
82
|
+
private lockTables?;
|
|
83
|
+
private subQueries;
|
|
84
|
+
private _mainAlias?;
|
|
85
|
+
private _aliases;
|
|
86
|
+
private _helper?;
|
|
87
|
+
private readonly platform;
|
|
88
|
+
private readonly knex;
|
|
89
|
+
/**
|
|
90
|
+
* @internal
|
|
91
|
+
*/
|
|
92
|
+
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);
|
|
93
|
+
select(fields: Field<T> | Field<T>[], distinct?: boolean): SelectQueryBuilder<T>;
|
|
94
|
+
addSelect(fields: Field<T> | Field<T>[]): SelectQueryBuilder<T>;
|
|
95
|
+
distinct(): SelectQueryBuilder<T>;
|
|
96
|
+
/** postgres only */
|
|
97
|
+
distinctOn(fields: string | string[]): SelectQueryBuilder<T>;
|
|
98
|
+
insert(data: RequiredEntityData<T> | RequiredEntityData<T>[]): InsertQueryBuilder<T>;
|
|
99
|
+
update(data: EntityData<T>): UpdateQueryBuilder<T>;
|
|
100
|
+
delete(cond?: QBFilterQuery): DeleteQueryBuilder<T>;
|
|
101
|
+
truncate(): TruncateQueryBuilder<T>;
|
|
102
|
+
count(field?: string | string[], distinct?: boolean): CountQueryBuilder<T>;
|
|
103
|
+
join(field: string | Knex.QueryBuilder | QueryBuilder<any>, alias: string, cond?: QBFilterQuery, type?: JoinType, path?: string, schema?: string): this;
|
|
104
|
+
innerJoin(field: string | Knex.QueryBuilder | QueryBuilder<any>, alias: string, cond?: QBFilterQuery, schema?: string): this;
|
|
105
|
+
innerJoinLateral(field: string | Knex.QueryBuilder | QueryBuilder<any>, alias: string, cond?: QBFilterQuery, schema?: string): this;
|
|
106
|
+
leftJoin(field: string | Knex.QueryBuilder | QueryBuilder<any>, alias: string, cond?: QBFilterQuery, schema?: string): this;
|
|
107
|
+
leftJoinLateral(field: string | Knex.QueryBuilder | QueryBuilder<any>, alias: string, cond?: QBFilterQuery, schema?: string): this;
|
|
108
|
+
joinAndSelect(field: string | [field: string, qb: Knex.QueryBuilder | QueryBuilder<any>], alias: string, cond?: QBFilterQuery, type?: JoinType, path?: string, fields?: string[], schema?: string): SelectQueryBuilder<T>;
|
|
109
|
+
leftJoinAndSelect(field: string | [field: string, qb: Knex.QueryBuilder | QueryBuilder<any>], alias: string, cond?: QBFilterQuery, fields?: string[], schema?: string): SelectQueryBuilder<T>;
|
|
110
|
+
leftJoinLateralAndSelect(field: string | [field: string, qb: Knex.QueryBuilder | QueryBuilder<any>], alias: string, cond?: QBFilterQuery, fields?: string[], schema?: string): SelectQueryBuilder<T>;
|
|
111
|
+
innerJoinAndSelect(field: string | [field: string, qb: Knex.QueryBuilder | QueryBuilder<any>], alias: string, cond?: QBFilterQuery, fields?: string[], schema?: string): SelectQueryBuilder<T>;
|
|
112
|
+
innerJoinLateralAndSelect(field: string | [field: string, qb: Knex.QueryBuilder | QueryBuilder<any>], alias: string, cond?: QBFilterQuery, fields?: string[], schema?: string): SelectQueryBuilder<T>;
|
|
113
|
+
protected getFieldsForJoinedLoad(prop: EntityProperty<T>, alias: string, explicitFields?: string[]): Field<T>[];
|
|
114
|
+
withSubQuery(subQuery: Knex.QueryBuilder, alias: string): this;
|
|
115
|
+
where(cond: QBFilterQuery<T>, operator?: keyof typeof GroupOperator): this;
|
|
116
|
+
where(cond: string, params?: any[], operator?: keyof typeof GroupOperator): this;
|
|
117
|
+
andWhere(cond: QBFilterQuery<T>): this;
|
|
118
|
+
andWhere(cond: string, params?: any[]): this;
|
|
119
|
+
orWhere(cond: QBFilterQuery<T>): this;
|
|
120
|
+
orWhere(cond: string, params?: any[]): this;
|
|
121
|
+
orderBy(orderBy: QBQueryOrderMap<T> | QBQueryOrderMap<T>[]): SelectQueryBuilder<T>;
|
|
122
|
+
groupBy(fields: (string | keyof T) | readonly (string | keyof T)[]): SelectQueryBuilder<T>;
|
|
123
|
+
having(cond?: QBFilterQuery | string, params?: any[]): SelectQueryBuilder<T>;
|
|
124
|
+
onConflict(fields?: Field<T> | Field<T>[]): InsertQueryBuilder<T>;
|
|
125
|
+
ignore(): this;
|
|
126
|
+
merge(data?: EntityData<T> | Field<T>[]): this;
|
|
127
|
+
returning(fields?: Field<T> | Field<T>[]): this;
|
|
128
|
+
/**
|
|
129
|
+
* @internal
|
|
130
|
+
*/
|
|
131
|
+
populate(populate: PopulateOptions<T>[], populateWhere?: ObjectQuery<T> | PopulateHint | `${PopulateHint}`): this;
|
|
132
|
+
limit(limit?: number, offset?: number): SelectQueryBuilder<T>;
|
|
133
|
+
offset(offset?: number): SelectQueryBuilder<T>;
|
|
134
|
+
withSchema(schema?: string): this;
|
|
135
|
+
setLockMode(mode?: LockMode, tables?: string[]): this;
|
|
136
|
+
setFlushMode(flushMode?: FlushMode): this;
|
|
137
|
+
setFlag(flag: QueryFlag): this;
|
|
138
|
+
unsetFlag(flag: QueryFlag): this;
|
|
139
|
+
hasFlag(flag: QueryFlag): boolean;
|
|
140
|
+
cache(config?: boolean | number | [string, number]): this;
|
|
141
|
+
/**
|
|
142
|
+
* Adds index hint to the FROM clause.
|
|
143
|
+
*/
|
|
144
|
+
indexHint(sql: string): this;
|
|
145
|
+
/**
|
|
146
|
+
* Prepend comment to the sql query using the syntax `/* ... *‍/`. Some characters are forbidden such as `/*, *‍/` and `?`.
|
|
147
|
+
*/
|
|
148
|
+
comment(comment: string | string[]): this;
|
|
149
|
+
/**
|
|
150
|
+
* Add hints to the query using comment-like syntax `/*+ ... *‍/`. MySQL and Oracle use this syntax for optimizer hints.
|
|
151
|
+
* Also various DB proxies and routers use this syntax to pass hints to alter their behavior. In other dialects the hints
|
|
152
|
+
* are ignored as simple comments.
|
|
153
|
+
*/
|
|
154
|
+
hintComment(comment: string | string[]): this;
|
|
155
|
+
/**
|
|
156
|
+
* Specifies FROM which entity's table select/update/delete will be executed, removing all previously set FROM-s.
|
|
157
|
+
* Allows setting a main string alias of the selection data.
|
|
158
|
+
*/
|
|
159
|
+
from<T extends AnyEntity<T> = AnyEntity>(target: QueryBuilder<T>, aliasName?: string): SelectQueryBuilder<T>;
|
|
160
|
+
from<T extends AnyEntity<T> = AnyEntity>(target: EntityName<T>): SelectQueryBuilder<T>;
|
|
161
|
+
getKnexQuery(processVirtualEntity?: boolean): Knex.QueryBuilder;
|
|
162
|
+
/**
|
|
163
|
+
* @internal
|
|
164
|
+
*/
|
|
165
|
+
clearRawFragmentsCache(): void;
|
|
166
|
+
/**
|
|
167
|
+
* Returns the query with parameters as wildcards.
|
|
168
|
+
*/
|
|
169
|
+
getQuery(): string;
|
|
170
|
+
toQuery(): {
|
|
171
|
+
sql: string;
|
|
172
|
+
_sql: Knex.Sql;
|
|
173
|
+
params: readonly unknown[];
|
|
174
|
+
};
|
|
175
|
+
/**
|
|
176
|
+
* Returns the list of all parameters for this query.
|
|
177
|
+
*/
|
|
178
|
+
getParams(): readonly Knex.Value[];
|
|
179
|
+
/**
|
|
180
|
+
* Returns raw interpolated query string with all the parameters inlined.
|
|
181
|
+
*/
|
|
182
|
+
getFormattedQuery(): string;
|
|
183
|
+
/**
|
|
184
|
+
* @internal
|
|
185
|
+
*/
|
|
186
|
+
getAliasForJoinPath(path?: string | JoinOptions, options?: ICriteriaNodeProcessOptions): string | undefined;
|
|
187
|
+
/**
|
|
188
|
+
* @internal
|
|
189
|
+
*/
|
|
190
|
+
getJoinForPath(path: string, options?: ICriteriaNodeProcessOptions): JoinOptions | undefined;
|
|
191
|
+
/**
|
|
192
|
+
* @internal
|
|
193
|
+
*/
|
|
194
|
+
getNextAlias(entityName?: string): string;
|
|
195
|
+
/**
|
|
196
|
+
* @internal
|
|
197
|
+
*/
|
|
198
|
+
getAliasMap(): Dictionary<string>;
|
|
199
|
+
/**
|
|
200
|
+
* Executes this QB and returns the raw results, mapped to the property names (unless disabled via last parameter).
|
|
201
|
+
* Use `method` to specify what kind of result you want to get (array/single/meta).
|
|
202
|
+
*/
|
|
203
|
+
execute<U = any>(method?: "all" | "get" | "run", options?: ExecuteOptions | boolean): Promise<U>;
|
|
204
|
+
/**
|
|
205
|
+
* Alias for `qb.getResultList()`
|
|
206
|
+
*/
|
|
207
|
+
getResult(): Promise<T[]>;
|
|
208
|
+
/**
|
|
209
|
+
* Executes the query, returning array of results
|
|
210
|
+
*/
|
|
211
|
+
getResultList(limit?: number): Promise<T[]>;
|
|
212
|
+
/**
|
|
213
|
+
* Executes the query, returning the first result or null
|
|
214
|
+
*/
|
|
215
|
+
getSingleResult(): Promise<T | null>;
|
|
216
|
+
/**
|
|
217
|
+
* Executes count query (without offset and limit), returning total count of results
|
|
218
|
+
*/
|
|
219
|
+
getCount(field?: string | string[], distinct?: boolean): Promise<number>;
|
|
220
|
+
/**
|
|
221
|
+
* Executes the query, returning both array of results and total count query (without offset and limit).
|
|
222
|
+
*/
|
|
223
|
+
getResultAndCount(): Promise<[T[], number]>;
|
|
224
|
+
/**
|
|
225
|
+
* Provides promise-like interface so we can await the QB instance.
|
|
226
|
+
*/
|
|
227
|
+
then<TResult1 = any, TResult2 = never>(onfulfilled?: ((value: any) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<T[] | number | QueryResult<T>>;
|
|
228
|
+
/**
|
|
229
|
+
* Returns knex instance with sub-query aliased with given alias.
|
|
230
|
+
* You can provide `EntityName.propName` as alias, then the field name will be used based on the metadata
|
|
231
|
+
*/
|
|
232
|
+
as(alias: string): Knex.QueryBuilder;
|
|
233
|
+
clone(reset?: boolean | string[]): QueryBuilder<T>;
|
|
234
|
+
getKnex(processVirtualEntity?: boolean): Knex.QueryBuilder;
|
|
235
|
+
private fromVirtual;
|
|
236
|
+
private joinReference;
|
|
237
|
+
private prepareFields;
|
|
238
|
+
private init;
|
|
239
|
+
private getQueryBase;
|
|
240
|
+
private applyDiscriminatorCondition;
|
|
241
|
+
private finalize;
|
|
242
|
+
private processPopulateWhere;
|
|
243
|
+
private hasToManyJoins;
|
|
244
|
+
private wrapPaginateSubQuery;
|
|
245
|
+
private wrapModifySubQuery;
|
|
246
|
+
private getSchema;
|
|
247
|
+
private createAlias;
|
|
248
|
+
private createMainAlias;
|
|
249
|
+
private fromSubQuery;
|
|
250
|
+
private fromEntityName;
|
|
251
|
+
private createQueryBuilderHelper;
|
|
252
|
+
private ensureFromClause;
|
|
253
|
+
private ensureNotFinalized;
|
|
254
|
+
/** @ignore */
|
|
255
|
+
[inspect.custom](depth: number): string;
|
|
256
|
+
}
|
|
257
|
+
export interface RunQueryBuilder<T extends object> extends Omit<QueryBuilder<T>, "getResult" | "getSingleResult" | "getResultList" | "where"> {
|
|
258
|
+
where(cond: QBFilterQuery<T> | string, params?: keyof typeof GroupOperator | any[], operator?: keyof typeof GroupOperator): this;
|
|
259
|
+
execute<U = QueryResult<T>>(method?: "all" | "get" | "run", mapResults?: boolean): Promise<U>;
|
|
260
|
+
then<TResult1 = QueryResult<T>, TResult2 = never>(onfulfilled?: ((value: QueryResult<T>) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<QueryResult<T>>;
|
|
261
|
+
}
|
|
262
|
+
export interface SelectQueryBuilder<T extends object> extends QueryBuilder<T> {
|
|
263
|
+
execute<U = T[]>(method?: "all" | "get" | "run", mapResults?: boolean): Promise<U>;
|
|
264
|
+
execute<U = T[]>(method: "all", mapResults?: boolean): Promise<U>;
|
|
265
|
+
execute<U = T>(method: "get", mapResults?: boolean): Promise<U>;
|
|
266
|
+
execute<U = QueryResult<T>>(method: "run", mapResults?: boolean): Promise<U>;
|
|
267
|
+
then<TResult1 = T[], TResult2 = never>(onfulfilled?: ((value: T[]) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<T[]>;
|
|
268
|
+
}
|
|
269
|
+
export interface CountQueryBuilder<T extends object> extends QueryBuilder<T> {
|
|
270
|
+
execute<U = {
|
|
271
|
+
count: number;
|
|
272
|
+
}[]>(method?: "all" | "get" | "run", mapResults?: boolean): Promise<U>;
|
|
273
|
+
execute<U = {
|
|
274
|
+
count: number;
|
|
275
|
+
}[]>(method: "all", mapResults?: boolean): Promise<U>;
|
|
276
|
+
execute<U = {
|
|
277
|
+
count: number;
|
|
278
|
+
}>(method: "get", mapResults?: boolean): Promise<U>;
|
|
279
|
+
execute<U = QueryResult<{
|
|
280
|
+
count: number;
|
|
281
|
+
}>>(method: "run", mapResults?: boolean): Promise<U>;
|
|
282
|
+
then<TResult1 = number, TResult2 = never>(onfulfilled?: ((value: number) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<number>;
|
|
283
|
+
}
|
|
284
|
+
export interface InsertQueryBuilder<T extends object> extends RunQueryBuilder<T> {
|
|
285
|
+
}
|
|
286
|
+
export interface UpdateQueryBuilder<T extends object> extends RunQueryBuilder<T> {
|
|
287
|
+
}
|
|
288
|
+
export interface DeleteQueryBuilder<T extends object> extends RunQueryBuilder<T> {
|
|
289
|
+
}
|
|
290
|
+
export interface TruncateQueryBuilder<T extends object> extends RunQueryBuilder<T> {
|
|
291
|
+
}
|