@mikro-orm/sql 7.0.0-rc.2 → 7.0.0
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 +5 -4
- package/AbstractSqlConnection.js +20 -6
- package/AbstractSqlDriver.d.ts +19 -13
- package/AbstractSqlDriver.js +225 -47
- package/AbstractSqlPlatform.d.ts +35 -0
- package/AbstractSqlPlatform.js +51 -5
- package/PivotCollectionPersister.d.ts +2 -11
- package/PivotCollectionPersister.js +59 -59
- package/README.md +5 -4
- package/SqlEntityManager.d.ts +2 -2
- package/SqlEntityManager.js +5 -5
- package/dialects/index.d.ts +1 -0
- package/dialects/index.js +1 -0
- package/dialects/mssql/MsSqlNativeQueryBuilder.d.ts +2 -0
- package/dialects/mssql/MsSqlNativeQueryBuilder.js +8 -4
- package/dialects/mysql/BaseMySqlPlatform.d.ts +6 -0
- package/dialects/mysql/BaseMySqlPlatform.js +18 -2
- package/dialects/mysql/MySqlSchemaHelper.d.ts +1 -1
- package/dialects/mysql/MySqlSchemaHelper.js +25 -14
- package/dialects/oracledb/OracleDialect.d.ts +78 -0
- package/dialects/oracledb/OracleDialect.js +166 -0
- package/dialects/oracledb/OracleNativeQueryBuilder.d.ts +19 -0
- package/dialects/oracledb/OracleNativeQueryBuilder.js +249 -0
- package/dialects/oracledb/index.d.ts +2 -0
- package/dialects/oracledb/index.js +2 -0
- package/dialects/postgresql/BasePostgreSqlPlatform.d.ts +6 -0
- package/dialects/postgresql/BasePostgreSqlPlatform.js +49 -37
- package/dialects/postgresql/PostgreSqlSchemaHelper.js +75 -59
- package/dialects/sqlite/BaseSqliteConnection.js +2 -2
- package/dialects/sqlite/NodeSqliteDialect.js +3 -1
- package/dialects/sqlite/SqlitePlatform.d.ts +1 -0
- package/dialects/sqlite/SqlitePlatform.js +7 -1
- package/dialects/sqlite/SqliteSchemaHelper.js +23 -17
- package/index.d.ts +1 -1
- package/index.js +0 -1
- package/package.json +30 -30
- package/plugin/index.d.ts +1 -14
- package/plugin/index.js +13 -13
- package/plugin/transformer.d.ts +6 -22
- package/plugin/transformer.js +91 -82
- package/query/ArrayCriteriaNode.d.ts +1 -1
- package/query/CriteriaNode.js +28 -10
- package/query/CriteriaNodeFactory.js +20 -4
- package/query/NativeQueryBuilder.d.ts +28 -3
- package/query/NativeQueryBuilder.js +65 -3
- package/query/ObjectCriteriaNode.js +75 -31
- package/query/QueryBuilder.d.ts +199 -100
- package/query/QueryBuilder.js +544 -358
- package/query/QueryBuilderHelper.d.ts +18 -14
- package/query/QueryBuilderHelper.js +364 -147
- package/query/ScalarCriteriaNode.js +17 -8
- package/query/enums.d.ts +2 -0
- package/query/enums.js +2 -0
- package/query/raw.js +1 -1
- package/schema/DatabaseSchema.d.ts +7 -5
- package/schema/DatabaseSchema.js +68 -45
- package/schema/DatabaseTable.d.ts +8 -6
- package/schema/DatabaseTable.js +191 -107
- package/schema/SchemaComparator.d.ts +1 -3
- package/schema/SchemaComparator.js +76 -50
- package/schema/SchemaHelper.d.ts +2 -13
- package/schema/SchemaHelper.js +30 -9
- package/schema/SqlSchemaGenerator.d.ts +4 -14
- package/schema/SqlSchemaGenerator.js +26 -12
- package/typings.d.ts +10 -5
- package/tsconfig.build.tsbuildinfo +0 -1
package/query/QueryBuilder.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { type AnyEntity, type AutoPath, type Collection, type ConnectionType, type Dictionary, type EntityData, type EntityDTOFlat, type EntityDTOProp, type EntityKey, type EntityManager,
|
|
1
|
+
import { type AnyEntity, type AutoPath, type Collection, type ConnectionType, type Dictionary, type EntityData, type EntityDTOFlat, type EntityDTOProp, type EntityKey, type EntityManager, EntityMetadata, type EntityName, type EntityProperty, type ExpandProperty, type FilterObject, type FilterOptions, type FilterValue, type FlushMode, type GroupOperator, type Loaded, LockMode, type LoggingOptions, type MetadataStorage, type PrimaryProperty, type ObjectQuery, PopulateHint, type PopulateOptions, type PopulatePath, QueryFlag, type QueryOrderKeysFlat, type QueryOrderMap, type QueryResult, RawQueryFragment, type Raw, type RequiredEntityData, type Scalar, type SerializeDTO, type Subquery, type Transaction } from '@mikro-orm/core';
|
|
2
2
|
import { JoinType, QueryType } from './enums.js';
|
|
3
3
|
import type { AbstractSqlDriver } from '../AbstractSqlDriver.js';
|
|
4
4
|
import { type Alias, type OnConflictClause, QueryBuilderHelper } from './QueryBuilderHelper.js';
|
|
5
5
|
import type { SqlEntityManager } from '../SqlEntityManager.js';
|
|
6
6
|
import type { ICriteriaNodeProcessOptions, InternalField, JoinOptions } from '../typings.js';
|
|
7
7
|
import type { AbstractSqlPlatform } from '../AbstractSqlPlatform.js';
|
|
8
|
-
import { NativeQueryBuilder } from './NativeQueryBuilder.js';
|
|
8
|
+
import { type CteOptions, NativeQueryBuilder } from './NativeQueryBuilder.js';
|
|
9
9
|
export interface ExecuteOptions {
|
|
10
10
|
mapResults?: boolean;
|
|
11
11
|
mergeResults?: boolean;
|
|
@@ -84,7 +84,7 @@ type RawOrderKeys<RawAliases extends string> = {
|
|
|
84
84
|
export type ContextOrderByMap<Entity, RootAlias extends string = never, Context = never, RawAliases extends string = never> = QueryOrderMap<Entity> | ((IsNever<RootAlias> extends true ? {} : RootAliasOrderKeys<RootAlias, Entity>) & ([Context] extends [never] ? {} : ContextOrderKeys<Context>) & (IsNever<RawAliases> extends true ? {} : string extends RawAliases ? {} : RawOrderKeys<RawAliases>));
|
|
85
85
|
type AliasedPath<Alias extends string, Type, P extends string> = P extends `${Alias}.*` ? P : P extends `${Alias}.${infer Rest}` ? `${Alias}.${AutoPath<Type & object, Rest, `${PopulatePath.ALL}`>}` : never;
|
|
86
86
|
type ContextAliasedPath<Context, P extends string> = Context[keyof Context] extends infer Join ? Join extends any ? Join extends [string, infer Alias, infer Type, any] ? AliasedPath<Alias & string, Type, P> : never : never : never;
|
|
87
|
-
type NestedAutoPath<Entity, RootAlias extends string, Context, P extends string> = P extends `${string}:ref` ? never : P extends `${infer Path} as ${string}` ?
|
|
87
|
+
type NestedAutoPath<Entity, RootAlias extends string, Context, P extends string> = P extends `${string}:ref` ? never : P extends `${infer Path} as ${string}` ? AliasedPath<RootAlias, Entity, Path> | ContextAliasedPath<Context, Path> | AutoPath<Entity, Path, `${PopulatePath.ALL}`> extends never ? never : P : AliasedPath<RootAlias, Entity, P> | ContextAliasedPath<Context, P> | AutoPath<Entity, P, `${PopulatePath.ALL}`>;
|
|
88
88
|
type AliasedObjectQuery<Entity extends object, Alias extends string> = {
|
|
89
89
|
[K in EntityKey<Entity> as `${Alias}.${K}`]?: ObjectQuery<Entity>[K];
|
|
90
90
|
};
|
|
@@ -96,7 +96,7 @@ type JoinCondition<JoinedEntity extends object, Alias extends string> = (ObjectQ
|
|
|
96
96
|
type RawJoinCondition = {
|
|
97
97
|
[key: string]: FilterValue<Scalar> | RawQueryFragment;
|
|
98
98
|
};
|
|
99
|
-
type ExtractRawAliasFromField<F> = F extends RawQueryFragment<infer A> ?
|
|
99
|
+
type ExtractRawAliasFromField<F> = F extends RawQueryFragment<infer A> ? A extends string ? A : never : F extends `${string} as ${infer A}` ? A : never;
|
|
100
100
|
type ExtractRawAliasesFromTuple<T extends readonly unknown[]> = T extends readonly [infer Head, ...infer Tail] ? ExtractRawAliasFromField<Head> | ExtractRawAliasesFromTuple<Tail> : never;
|
|
101
101
|
type ExtractRawAliases<Fields> = Fields extends readonly unknown[] ? ExtractRawAliasesFromTuple<Fields> : ExtractRawAliasFromField<Fields>;
|
|
102
102
|
type FlatOperatorMap = {
|
|
@@ -139,6 +139,57 @@ type GroupOperators<RootAlias extends string, Context, Entity, RawAliases extend
|
|
|
139
139
|
};
|
|
140
140
|
export type AliasedFilterCondition<RootAlias extends string, Context, Entity, RawAliases extends string = never> = (IsNever<RootAlias> extends true ? {} : string extends RootAlias ? {} : RootAliasFilterKeys<RootAlias, Entity>) & ([Context] extends [never] ? {} : ContextFilterKeys<Context>) & (IsNever<RawAliases> extends true ? {} : string extends RawAliases ? {} : RawFilterKeys<RawAliases>) & GroupOperators<RootAlias, Context, Entity, RawAliases>;
|
|
141
141
|
export type QBFilterQuery<Entity, RootAlias extends string = never, Context = never, RawAliases extends string = never> = FilterObject<Entity> & AliasedFilterCondition<RootAlias, Context, Entity, RawAliases>;
|
|
142
|
+
/** @internal */
|
|
143
|
+
export interface QBState<Entity extends object> {
|
|
144
|
+
type?: QueryType;
|
|
145
|
+
fields?: InternalField<Entity>[];
|
|
146
|
+
populate: PopulateOptions<Entity>[];
|
|
147
|
+
populateWhere?: ObjectQuery<Entity> | PopulateHint | `${PopulateHint}`;
|
|
148
|
+
populateFilter?: ObjectQuery<Entity> | PopulateHint | `${PopulateHint}`;
|
|
149
|
+
resolvedPopulateWhere?: ObjectQuery<Entity> | PopulateHint | `${PopulateHint}`;
|
|
150
|
+
populateMap: Dictionary<string>;
|
|
151
|
+
aliasCounter: number;
|
|
152
|
+
flags: Set<QueryFlag>;
|
|
153
|
+
finalized: boolean;
|
|
154
|
+
populateHintFinalized: boolean;
|
|
155
|
+
joins: Dictionary<JoinOptions>;
|
|
156
|
+
explicitAlias: boolean;
|
|
157
|
+
schema?: string;
|
|
158
|
+
cond: Dictionary;
|
|
159
|
+
data?: Dictionary;
|
|
160
|
+
orderBy: QueryOrderMap<Entity>[];
|
|
161
|
+
groupBy: InternalField<Entity>[];
|
|
162
|
+
having: Dictionary;
|
|
163
|
+
returning?: InternalField<Entity>[];
|
|
164
|
+
onConflict?: OnConflictClause<Entity>[];
|
|
165
|
+
limit?: number;
|
|
166
|
+
offset?: number;
|
|
167
|
+
distinctOn?: string[];
|
|
168
|
+
joinedProps: Map<string, PopulateOptions<any>>;
|
|
169
|
+
cache?: boolean | number | [string, number];
|
|
170
|
+
indexHint?: string;
|
|
171
|
+
collation?: string;
|
|
172
|
+
comments: string[];
|
|
173
|
+
hintComments: string[];
|
|
174
|
+
flushMode?: FlushMode;
|
|
175
|
+
lockMode?: LockMode;
|
|
176
|
+
lockTables?: string[];
|
|
177
|
+
subQueries: Dictionary<string>;
|
|
178
|
+
mainAlias?: Alias<Entity>;
|
|
179
|
+
aliases: Dictionary<Alias<any>>;
|
|
180
|
+
tptAlias: Dictionary<string>;
|
|
181
|
+
unionQuery?: {
|
|
182
|
+
sql: string;
|
|
183
|
+
params: readonly unknown[];
|
|
184
|
+
};
|
|
185
|
+
ctes: (CteOptions & {
|
|
186
|
+
name: string;
|
|
187
|
+
query: NativeQueryBuilder | RawQueryFragment;
|
|
188
|
+
recursive?: boolean;
|
|
189
|
+
})[];
|
|
190
|
+
tptJoinsApplied: boolean;
|
|
191
|
+
autoJoinedPaths: string[];
|
|
192
|
+
}
|
|
142
193
|
/**
|
|
143
194
|
* SQL query builder with fluent interface.
|
|
144
195
|
*
|
|
@@ -158,7 +209,8 @@ export type QBFilterQuery<Entity, RootAlias extends string = never, Context = ne
|
|
|
158
209
|
* const publisher = await qb.getSingleResult();
|
|
159
210
|
* ```
|
|
160
211
|
*/
|
|
161
|
-
export declare class QueryBuilder<Entity extends object = AnyEntity, RootAlias extends string = never, Hint extends string = never, Context extends object = never, RawAliases extends string = never, Fields extends string = '*'> implements Subquery {
|
|
212
|
+
export declare class QueryBuilder<Entity extends object = AnyEntity, RootAlias extends string = never, Hint extends string = never, Context extends object = never, RawAliases extends string = never, Fields extends string = '*', CTEs extends Record<string, object> = {}> implements Subquery {
|
|
213
|
+
#private;
|
|
162
214
|
protected readonly metadata: MetadataStorage;
|
|
163
215
|
protected readonly driver: AbstractSqlDriver;
|
|
164
216
|
protected readonly context?: Transaction | undefined;
|
|
@@ -166,63 +218,15 @@ export declare class QueryBuilder<Entity extends object = AnyEntity, RootAlias e
|
|
|
166
218
|
protected em?: SqlEntityManager | undefined;
|
|
167
219
|
protected loggerContext?: (LoggingOptions & Dictionary) | undefined;
|
|
168
220
|
readonly __subquery: true;
|
|
221
|
+
/** @internal */
|
|
222
|
+
static createDefaultState<T extends object>(): QBState<T>;
|
|
169
223
|
get mainAlias(): Alias<Entity>;
|
|
170
224
|
get alias(): string;
|
|
171
225
|
get helper(): QueryBuilderHelper;
|
|
172
226
|
get type(): QueryType;
|
|
173
227
|
/** @internal */
|
|
174
|
-
|
|
175
|
-
/** @internal */
|
|
176
|
-
_fields?: InternalField<Entity>[];
|
|
177
|
-
/** @internal */
|
|
178
|
-
_populate: PopulateOptions<Entity>[];
|
|
179
|
-
/** @internal */
|
|
180
|
-
_populateWhere?: ObjectQuery<Entity> | PopulateHint | `${PopulateHint}`;
|
|
181
|
-
/** @internal */
|
|
182
|
-
_populateFilter?: ObjectQuery<Entity> | PopulateHint | `${PopulateHint}`;
|
|
183
|
-
/** @internal */
|
|
184
|
-
__populateWhere?: ObjectQuery<Entity> | PopulateHint | `${PopulateHint}`;
|
|
185
|
-
/** @internal */
|
|
186
|
-
_populateMap: Dictionary<string>;
|
|
187
|
-
protected aliasCounter: number;
|
|
188
|
-
protected flags: Set<QueryFlag>;
|
|
189
|
-
protected finalized: boolean;
|
|
190
|
-
protected populateHintFinalized: boolean;
|
|
191
|
-
protected _joins: Dictionary<JoinOptions>;
|
|
192
|
-
protected _explicitAlias: boolean;
|
|
193
|
-
protected _schema?: string;
|
|
194
|
-
protected _cond: Dictionary;
|
|
195
|
-
protected _data: Dictionary;
|
|
196
|
-
protected _orderBy: QueryOrderMap<Entity>[];
|
|
197
|
-
protected _groupBy: InternalField<Entity>[];
|
|
198
|
-
protected _having: Dictionary;
|
|
199
|
-
protected _returning?: InternalField<Entity>[];
|
|
200
|
-
protected _onConflict?: OnConflictClause<Entity>[];
|
|
201
|
-
protected _limit?: number;
|
|
202
|
-
protected _offset?: number;
|
|
203
|
-
protected _distinctOn?: string[];
|
|
204
|
-
protected _joinedProps: Map<string, PopulateOptions<any>>;
|
|
205
|
-
protected _cache?: boolean | number | [string, number];
|
|
206
|
-
protected _indexHint?: string;
|
|
207
|
-
protected _collation?: string;
|
|
208
|
-
protected _comments: string[];
|
|
209
|
-
protected _hintComments: string[];
|
|
210
|
-
protected flushMode?: FlushMode;
|
|
211
|
-
protected lockMode?: LockMode;
|
|
212
|
-
protected lockTables?: string[];
|
|
213
|
-
protected subQueries: Dictionary<string>;
|
|
214
|
-
protected _mainAlias?: Alias<Entity>;
|
|
215
|
-
protected _aliases: Dictionary<Alias<any>>;
|
|
216
|
-
protected _tptAlias: Dictionary<string>;
|
|
217
|
-
protected _helper?: QueryBuilderHelper;
|
|
218
|
-
protected _query?: {
|
|
219
|
-
sql?: string;
|
|
220
|
-
params?: readonly unknown[];
|
|
221
|
-
qb: NativeQueryBuilder;
|
|
222
|
-
};
|
|
228
|
+
get state(): QBState<Entity>;
|
|
223
229
|
protected readonly platform: AbstractSqlPlatform;
|
|
224
|
-
private tptJoinsApplied;
|
|
225
|
-
private readonly autoJoinedPaths;
|
|
226
230
|
/**
|
|
227
231
|
* @internal
|
|
228
232
|
*/
|
|
@@ -247,7 +251,7 @@ export declare class QueryBuilder<Entity extends object = AnyEntity, RootAlias e
|
|
|
247
251
|
* qb.select('*', true);
|
|
248
252
|
* ```
|
|
249
253
|
*/
|
|
250
|
-
select<const F extends readonly Field<Entity, RootAlias, Context>[]>(fields: F, distinct?: boolean): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases | ExtractRawAliases<F>, ExtractRootFields<F[number] & string, RootAlias, Context
|
|
254
|
+
select<const F extends readonly Field<Entity, RootAlias, Context>[]>(fields: F, distinct?: boolean): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases | ExtractRawAliases<F>, ExtractRootFields<F[number] & string, RootAlias, Context>, CTEs>;
|
|
251
255
|
/**
|
|
252
256
|
* Creates a SELECT query, specifying the fields to retrieve.
|
|
253
257
|
*
|
|
@@ -264,7 +268,7 @@ export declare class QueryBuilder<Entity extends object = AnyEntity, RootAlias e
|
|
|
264
268
|
* qb.select('*', true);
|
|
265
269
|
* ```
|
|
266
270
|
*/
|
|
267
|
-
select<const P extends string>(fields: readonly NestedAutoPath<Entity, RootAlias, Context, P>[], distinct?: boolean): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, ExtractRootFields<P, RootAlias, Context
|
|
271
|
+
select<const P extends string>(fields: readonly NestedAutoPath<Entity, RootAlias, Context, P>[], distinct?: boolean): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, ExtractRootFields<P, RootAlias, Context>, CTEs>;
|
|
268
272
|
/**
|
|
269
273
|
* Creates a SELECT query, specifying the fields to retrieve.
|
|
270
274
|
*
|
|
@@ -275,7 +279,7 @@ export declare class QueryBuilder<Entity extends object = AnyEntity, RootAlias e
|
|
|
275
279
|
* qb.select('address.city');
|
|
276
280
|
* ```
|
|
277
281
|
*/
|
|
278
|
-
select<const P extends string>(fields: NestedAutoPath<Entity, RootAlias, Context, P>, distinct?: boolean): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, ExtractRootFields<P, RootAlias, Context
|
|
282
|
+
select<const P extends string>(fields: NestedAutoPath<Entity, RootAlias, Context, P>, distinct?: boolean): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, ExtractRootFields<P, RootAlias, Context>, CTEs>;
|
|
279
283
|
/**
|
|
280
284
|
* Creates a SELECT query, specifying the fields to retrieve.
|
|
281
285
|
*
|
|
@@ -292,16 +296,16 @@ export declare class QueryBuilder<Entity extends object = AnyEntity, RootAlias e
|
|
|
292
296
|
* qb.select('*', true);
|
|
293
297
|
* ```
|
|
294
298
|
*/
|
|
295
|
-
select<const F extends Field<Entity, RootAlias, Context>>(fields: F, distinct?: boolean): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases | ExtractRawAliases<readonly [F]>, ExtractRootFields<F & string, RootAlias, Context
|
|
299
|
+
select<const F extends Field<Entity, RootAlias, Context>>(fields: F, distinct?: boolean): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases | ExtractRawAliases<readonly [F]>, ExtractRootFields<F & string, RootAlias, Context>, CTEs>;
|
|
296
300
|
/**
|
|
297
301
|
* Adds fields to an existing SELECT query.
|
|
298
302
|
*/
|
|
299
|
-
addSelect<const F extends Field<Entity, RootAlias, Context> | readonly Field<Entity, RootAlias, Context>[]>(fields: F): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases | ExtractRawAliases<F extends readonly unknown[] ? F : [F]>, Fields | ExtractRootFields<F extends readonly (infer U)[] ? U & string : F & string, RootAlias, Context
|
|
300
|
-
distinct(): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields>;
|
|
303
|
+
addSelect<const F extends Field<Entity, RootAlias, Context> | readonly Field<Entity, RootAlias, Context>[]>(fields: F): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases | ExtractRawAliases<F extends readonly unknown[] ? F : [F]>, Fields | ExtractRootFields<F extends readonly (infer U)[] ? U & string : F & string, RootAlias, Context>, CTEs>;
|
|
304
|
+
distinct(): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields, CTEs>;
|
|
301
305
|
/** postgres only */
|
|
302
|
-
distinctOn<const F extends readonly Field<Entity, RootAlias, Context>[]>(fields: F): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields>;
|
|
306
|
+
distinctOn<const F extends readonly Field<Entity, RootAlias, Context>[]>(fields: F): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields, CTEs>;
|
|
303
307
|
/** postgres only */
|
|
304
|
-
distinctOn<F extends Field<Entity, RootAlias, Context>>(fields: F): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields>;
|
|
308
|
+
distinctOn<F extends Field<Entity, RootAlias, Context>>(fields: F): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields, CTEs>;
|
|
305
309
|
/**
|
|
306
310
|
* Creates an INSERT query with the given data.
|
|
307
311
|
*
|
|
@@ -376,29 +380,29 @@ export declare class QueryBuilder<Entity extends object = AnyEntity, RootAlias e
|
|
|
376
380
|
* .where({ 'a.name': 'John' });
|
|
377
381
|
* ```
|
|
378
382
|
*/
|
|
379
|
-
join<Field extends QBField<Entity, RootAlias, Context>, Alias extends string>(field: Field, alias: Alias, cond?: JoinCondition<JoinedEntityType<Entity, Context, Field & string>, Alias>, type?: JoinType, path?: string, schema?: string): SelectQueryBuilder<Entity, RootAlias, ModifyHint<RootAlias, Context, Hint, Field> & {}, ModifyContext<Entity, Context, Field, Alias>, RawAliases>;
|
|
383
|
+
join<Field extends QBField<Entity, RootAlias, Context>, Alias extends string>(field: Field, alias: Alias, cond?: JoinCondition<JoinedEntityType<Entity, Context, Field & string>, Alias>, type?: JoinType, path?: string, schema?: string): SelectQueryBuilder<Entity, RootAlias, ModifyHint<RootAlias, Context, Hint, Field> & {}, ModifyContext<Entity, Context, Field, Alias>, RawAliases, '*', CTEs>;
|
|
380
384
|
/**
|
|
381
385
|
* Adds a JOIN clause to the query for a subquery.
|
|
382
386
|
*/
|
|
383
|
-
join<Alias extends string>(field: RawQueryFragment | QueryBuilder<any>, alias: Alias, cond?: RawJoinCondition, type?: JoinType, path?: string, schema?: string): SelectQueryBuilder<Entity, RootAlias, Hint, ModifyContext<Entity, Context, string, Alias>, RawAliases>;
|
|
387
|
+
join<Alias extends string>(field: RawQueryFragment | QueryBuilder<any>, alias: Alias, cond?: RawJoinCondition, type?: JoinType, path?: string, schema?: string): SelectQueryBuilder<Entity, RootAlias, Hint, ModifyContext<Entity, Context, string, Alias>, RawAliases, '*', CTEs>;
|
|
384
388
|
/**
|
|
385
389
|
* Adds an INNER JOIN clause to the query for an entity relation.
|
|
386
390
|
*/
|
|
387
|
-
innerJoin<Field extends QBField<Entity, RootAlias, Context>, Alias extends string>(field: Field, alias: Alias, cond?: JoinCondition<JoinedEntityType<Entity, Context, Field & string>, Alias>, schema?: string): SelectQueryBuilder<Entity, RootAlias, ModifyHint<RootAlias, Context, Hint, Field> & {}, ModifyContext<Entity, Context, Field, Alias>, RawAliases>;
|
|
391
|
+
innerJoin<Field extends QBField<Entity, RootAlias, Context>, Alias extends string>(field: Field, alias: Alias, cond?: JoinCondition<JoinedEntityType<Entity, Context, Field & string>, Alias>, schema?: string): SelectQueryBuilder<Entity, RootAlias, ModifyHint<RootAlias, Context, Hint, Field> & {}, ModifyContext<Entity, Context, Field, Alias>, RawAliases, '*', CTEs>;
|
|
388
392
|
/**
|
|
389
393
|
* Adds an INNER JOIN clause to the query for a subquery.
|
|
390
394
|
*/
|
|
391
|
-
innerJoin<Alias extends string>(field: RawQueryFragment | QueryBuilder<any>, alias: Alias, cond?: RawJoinCondition, schema?: string): SelectQueryBuilder<Entity, RootAlias, Hint, ModifyContext<Entity, Context, string, Alias>, RawAliases>;
|
|
392
|
-
innerJoinLateral<Alias extends string>(field: RawQueryFragment | QueryBuilder<any>, alias: Alias, cond?: RawJoinCondition, schema?: string): SelectQueryBuilder<Entity, RootAlias, Hint, ModifyContext<Entity, Context, string, Alias>, RawAliases>;
|
|
395
|
+
innerJoin<Alias extends string>(field: RawQueryFragment | QueryBuilder<any>, alias: Alias, cond?: RawJoinCondition, schema?: string): SelectQueryBuilder<Entity, RootAlias, Hint, ModifyContext<Entity, Context, string, Alias>, RawAliases, '*', CTEs>;
|
|
396
|
+
innerJoinLateral<Alias extends string>(field: RawQueryFragment | QueryBuilder<any>, alias: Alias, cond?: RawJoinCondition, schema?: string): SelectQueryBuilder<Entity, RootAlias, Hint, ModifyContext<Entity, Context, string, Alias>, RawAliases, '*', CTEs>;
|
|
393
397
|
/**
|
|
394
398
|
* Adds a LEFT JOIN clause to the query for an entity relation.
|
|
395
399
|
*/
|
|
396
|
-
leftJoin<Field extends QBField<Entity, RootAlias, Context>, Alias extends string>(field: Field, alias: Alias, cond?: JoinCondition<JoinedEntityType<Entity, Context, Field & string>, Alias>, schema?: string): SelectQueryBuilder<Entity, RootAlias, ModifyHint<RootAlias, Context, Hint, Field> & {}, ModifyContext<Entity, Context, Field, Alias>, RawAliases>;
|
|
400
|
+
leftJoin<Field extends QBField<Entity, RootAlias, Context>, Alias extends string>(field: Field, alias: Alias, cond?: JoinCondition<JoinedEntityType<Entity, Context, Field & string>, Alias>, schema?: string): SelectQueryBuilder<Entity, RootAlias, ModifyHint<RootAlias, Context, Hint, Field> & {}, ModifyContext<Entity, Context, Field, Alias>, RawAliases, '*', CTEs>;
|
|
397
401
|
/**
|
|
398
402
|
* Adds a LEFT JOIN clause to the query for a subquery.
|
|
399
403
|
*/
|
|
400
|
-
leftJoin<Alias extends string>(field: RawQueryFragment | QueryBuilder<any>, alias: Alias, cond?: RawJoinCondition, schema?: string): SelectQueryBuilder<Entity, RootAlias, Hint, ModifyContext<Entity, Context, string, Alias>, RawAliases>;
|
|
401
|
-
leftJoinLateral<Alias extends string>(field: RawQueryFragment | QueryBuilder<any>, alias: Alias, cond?: RawJoinCondition, schema?: string): SelectQueryBuilder<Entity, RootAlias, Hint, ModifyContext<Entity, Context, string, Alias>, RawAliases>;
|
|
404
|
+
leftJoin<Alias extends string>(field: RawQueryFragment | QueryBuilder<any>, alias: Alias, cond?: RawJoinCondition, schema?: string): SelectQueryBuilder<Entity, RootAlias, Hint, ModifyContext<Entity, Context, string, Alias>, RawAliases, '*', CTEs>;
|
|
405
|
+
leftJoinLateral<Alias extends string>(field: RawQueryFragment | QueryBuilder<any>, alias: Alias, cond?: RawJoinCondition, schema?: string): SelectQueryBuilder<Entity, RootAlias, Hint, ModifyContext<Entity, Context, string, Alias>, RawAliases, '*', CTEs>;
|
|
402
406
|
/**
|
|
403
407
|
* Adds a JOIN clause and automatically selects the joined entity's fields.
|
|
404
408
|
* This is useful for eager loading related entities.
|
|
@@ -411,11 +415,26 @@ export declare class QueryBuilder<Entity extends object = AnyEntity, RootAlias e
|
|
|
411
415
|
* .where({ 'a.name': 'John' });
|
|
412
416
|
* ```
|
|
413
417
|
*/
|
|
414
|
-
joinAndSelect<Field extends QBField<Entity, RootAlias, Context>, Alias extends string, const JoinFields extends readonly [
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
418
|
+
joinAndSelect<Field extends QBField<Entity, RootAlias, Context>, Alias extends string, const JoinFields extends readonly [
|
|
419
|
+
JoinSelectField<JoinedEntityType<Entity, Context, Field & string>, Alias>,
|
|
420
|
+
...JoinSelectField<JoinedEntityType<Entity, Context, Field & string>, Alias>[]
|
|
421
|
+
] | undefined = undefined>(field: Field | [Field, RawQueryFragment | QueryBuilder<any>], alias: Alias, cond?: JoinCondition<JoinedEntityType<Entity, Context, Field & string>, Alias>, type?: JoinType, path?: string, fields?: JoinFields, schema?: string): SelectQueryBuilder<Entity, RootAlias, ModifyHint<RootAlias, Context, Hint, Field, true> & {}, ModifyContext<Entity, Context, Field, Alias, true>, RawAliases, ModifyFields<Fields, RootAlias, Context, Field, Alias, JoinFields>, CTEs>;
|
|
422
|
+
leftJoinAndSelect<Field extends QBField<Entity, RootAlias, Context>, Alias extends string, const JoinFields extends readonly [
|
|
423
|
+
JoinSelectField<JoinedEntityType<Entity, Context, Field & string>, Alias>,
|
|
424
|
+
...JoinSelectField<JoinedEntityType<Entity, Context, Field & string>, Alias>[]
|
|
425
|
+
] | undefined = undefined>(field: Field | [Field, RawQueryFragment | QueryBuilder<any>], alias: Alias, cond?: JoinCondition<JoinedEntityType<Entity, Context, Field & string>, Alias>, fields?: JoinFields, schema?: string): SelectQueryBuilder<Entity, RootAlias, ModifyHint<RootAlias, Context, Hint, Field, true> & {}, ModifyContext<Entity, Context, Field, Alias, true>, RawAliases, ModifyFields<Fields, RootAlias, Context, Field, Alias, JoinFields>, CTEs>;
|
|
426
|
+
leftJoinLateralAndSelect<Field extends QBField<Entity, RootAlias, Context>, Alias extends string, const JoinFields extends readonly [
|
|
427
|
+
JoinSelectField<JoinedEntityType<Entity, Context, Field & string>, Alias>,
|
|
428
|
+
...JoinSelectField<JoinedEntityType<Entity, Context, Field & string>, Alias>[]
|
|
429
|
+
] | undefined = undefined>(field: [Field, RawQueryFragment | QueryBuilder<any>], alias: Alias, cond?: JoinCondition<JoinedEntityType<Entity, Context, Field & string>, Alias>, fields?: JoinFields, schema?: string): SelectQueryBuilder<Entity, RootAlias, ModifyHint<RootAlias, Context, Hint, Field, true> & {}, ModifyContext<Entity, Context, Field, Alias, true>, RawAliases, ModifyFields<Fields, RootAlias, Context, Field, Alias, JoinFields>, CTEs>;
|
|
430
|
+
innerJoinAndSelect<Field extends QBField<Entity, RootAlias, Context>, Alias extends string, const JoinFields extends readonly [
|
|
431
|
+
JoinSelectField<JoinedEntityType<Entity, Context, Field & string>, Alias>,
|
|
432
|
+
...JoinSelectField<JoinedEntityType<Entity, Context, Field & string>, Alias>[]
|
|
433
|
+
] | undefined = undefined>(field: Field | [Field, RawQueryFragment | QueryBuilder<any>], alias: Alias, cond?: JoinCondition<JoinedEntityType<Entity, Context, Field & string>, Alias>, fields?: JoinFields, schema?: string): SelectQueryBuilder<Entity, RootAlias, ModifyHint<RootAlias, Context, Hint, Field, true> & {}, ModifyContext<Entity, Context, Field, Alias, true>, RawAliases, ModifyFields<Fields, RootAlias, Context, Field, Alias, JoinFields>, CTEs>;
|
|
434
|
+
innerJoinLateralAndSelect<Field extends QBField<Entity, RootAlias, Context>, Alias extends string, const JoinFields extends readonly [
|
|
435
|
+
JoinSelectField<JoinedEntityType<Entity, Context, Field & string>, Alias>,
|
|
436
|
+
...JoinSelectField<JoinedEntityType<Entity, Context, Field & string>, Alias>[]
|
|
437
|
+
] | undefined = undefined>(field: [Field, RawQueryFragment | QueryBuilder<any>], alias: Alias, cond?: JoinCondition<JoinedEntityType<Entity, Context, Field & string>, Alias>, fields?: JoinFields, schema?: string): SelectQueryBuilder<Entity, RootAlias, ModifyHint<RootAlias, Context, Hint, Field, true> & {}, ModifyContext<Entity, Context, Field, Alias, true>, RawAliases, ModifyFields<Fields, RootAlias, Context, Field, Alias, JoinFields>, CTEs>;
|
|
419
438
|
protected getFieldsForJoinedLoad(prop: EntityProperty<Entity>, alias: string, explicitFields?: readonly string[]): InternalField<Entity>[];
|
|
420
439
|
/**
|
|
421
440
|
* Apply filters to the QB where condition.
|
|
@@ -518,7 +537,7 @@ export declare class QueryBuilder<Entity extends object = AnyEntity, RootAlias e
|
|
|
518
537
|
* qb.orderBy({ 'profile.bio': 'asc' }); // nested via dot notation
|
|
519
538
|
* ```
|
|
520
539
|
*/
|
|
521
|
-
orderBy(orderBy: ContextOrderByMap<Entity, RootAlias, Context, RawAliases> | ContextOrderByMap<Entity, RootAlias, Context, RawAliases>[]): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields>;
|
|
540
|
+
orderBy(orderBy: ContextOrderByMap<Entity, RootAlias, Context, RawAliases> | ContextOrderByMap<Entity, RootAlias, Context, RawAliases>[]): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields, CTEs>;
|
|
522
541
|
/**
|
|
523
542
|
* Adds an ORDER BY clause to the query, replacing any existing order.
|
|
524
543
|
*
|
|
@@ -531,18 +550,18 @@ export declare class QueryBuilder<Entity extends object = AnyEntity, RootAlias e
|
|
|
531
550
|
* ```
|
|
532
551
|
*/
|
|
533
552
|
orderBy<const T extends Record<string, QueryOrderKeysFlat>>(orderBy: T & {
|
|
534
|
-
[K in keyof T]: K extends NestedAutoPath<Entity, RootAlias, Context, K & string> ? T[K] :
|
|
535
|
-
}): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields>;
|
|
553
|
+
[K in keyof T]: K extends NestedAutoPath<Entity, RootAlias, Context, K & string> ? T[K] : K extends RawAliases ? T[K] : never;
|
|
554
|
+
}): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields, CTEs>;
|
|
536
555
|
/**
|
|
537
556
|
* Adds additional ORDER BY clause without replacing existing order.
|
|
538
557
|
*/
|
|
539
|
-
andOrderBy(orderBy: ContextOrderByMap<Entity, RootAlias, Context, RawAliases> | ContextOrderByMap<Entity, RootAlias, Context, RawAliases>[]): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields>;
|
|
558
|
+
andOrderBy(orderBy: ContextOrderByMap<Entity, RootAlias, Context, RawAliases> | ContextOrderByMap<Entity, RootAlias, Context, RawAliases>[]): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields, CTEs>;
|
|
540
559
|
/**
|
|
541
560
|
* Adds additional ORDER BY clause without replacing existing order.
|
|
542
561
|
*/
|
|
543
562
|
andOrderBy<const T extends Record<string, QueryOrderKeysFlat>>(orderBy: T & {
|
|
544
|
-
[K in keyof T]: K extends NestedAutoPath<Entity, RootAlias, Context, K & string> ? T[K] :
|
|
545
|
-
}): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields>;
|
|
563
|
+
[K in keyof T]: K extends NestedAutoPath<Entity, RootAlias, Context, K & string> ? T[K] : K extends RawAliases ? T[K] : never;
|
|
564
|
+
}): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields, CTEs>;
|
|
546
565
|
private processOrderBy;
|
|
547
566
|
/** Collect custom aliases from select fields (stored as 'resolved as alias' strings by select()). */
|
|
548
567
|
private getSelectAliases;
|
|
@@ -555,7 +574,7 @@ export declare class QueryBuilder<Entity extends object = AnyEntity, RootAlias e
|
|
|
555
574
|
* .groupBy('status');
|
|
556
575
|
* ```
|
|
557
576
|
*/
|
|
558
|
-
groupBy<const F extends readonly Field<Entity, RootAlias, Context>[]>(fields: F): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields>;
|
|
577
|
+
groupBy<const F extends readonly Field<Entity, RootAlias, Context>[]>(fields: F): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields, CTEs>;
|
|
559
578
|
/**
|
|
560
579
|
* Adds a GROUP BY clause to the query.
|
|
561
580
|
*
|
|
@@ -565,7 +584,7 @@ export declare class QueryBuilder<Entity extends object = AnyEntity, RootAlias e
|
|
|
565
584
|
* .groupBy('status');
|
|
566
585
|
* ```
|
|
567
586
|
*/
|
|
568
|
-
groupBy<F extends Field<Entity, RootAlias, Context>>(fields: F): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields>;
|
|
587
|
+
groupBy<F extends Field<Entity, RootAlias, Context>>(fields: F): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields, CTEs>;
|
|
569
588
|
/**
|
|
570
589
|
* Adds a GROUP BY clause to the query.
|
|
571
590
|
*
|
|
@@ -575,7 +594,7 @@ export declare class QueryBuilder<Entity extends object = AnyEntity, RootAlias e
|
|
|
575
594
|
* .groupBy('status');
|
|
576
595
|
* ```
|
|
577
596
|
*/
|
|
578
|
-
groupBy<const P extends string>(fields: NestedAutoPath<Entity, RootAlias, Context, P> | readonly NestedAutoPath<Entity, RootAlias, Context, P>[]): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields>;
|
|
597
|
+
groupBy<const P extends string>(fields: NestedAutoPath<Entity, RootAlias, Context, P> | readonly NestedAutoPath<Entity, RootAlias, Context, P>[]): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields, CTEs>;
|
|
579
598
|
/**
|
|
580
599
|
* Adds a HAVING clause to the query, typically used with GROUP BY.
|
|
581
600
|
*
|
|
@@ -586,9 +605,9 @@ export declare class QueryBuilder<Entity extends object = AnyEntity, RootAlias e
|
|
|
586
605
|
* .having({ count: { $gt: 5 } });
|
|
587
606
|
* ```
|
|
588
607
|
*/
|
|
589
|
-
having(cond?: QBFilterQuery<Entity, RootAlias, Context, RawAliases> | string, params?: any[], operator?: keyof typeof GroupOperator): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields>;
|
|
590
|
-
andHaving(cond?: QBFilterQuery<Entity, RootAlias, Context, RawAliases> | string, params?: any[]): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields>;
|
|
591
|
-
orHaving(cond?: QBFilterQuery<Entity, RootAlias, Context, RawAliases> | string, params?: any[]): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields>;
|
|
608
|
+
having(cond?: QBFilterQuery<Entity, RootAlias, Context, RawAliases> | string, params?: any[], operator?: keyof typeof GroupOperator): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields, CTEs>;
|
|
609
|
+
andHaving(cond?: QBFilterQuery<Entity, RootAlias, Context, RawAliases> | string, params?: any[]): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields, CTEs>;
|
|
610
|
+
orHaving(cond?: QBFilterQuery<Entity, RootAlias, Context, RawAliases> | string, params?: any[]): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields, CTEs>;
|
|
592
611
|
onConflict<F extends Field<Entity, RootAlias, Context>>(fields?: F | F[] | RawQueryFragment): InsertQueryBuilder<Entity, RootAlias, Context>;
|
|
593
612
|
ignore(): this;
|
|
594
613
|
merge<const P extends string>(data: readonly NestedAutoPath<Entity, RootAlias, Context, P>[]): this;
|
|
@@ -607,7 +626,7 @@ export declare class QueryBuilder<Entity extends object = AnyEntity, RootAlias e
|
|
|
607
626
|
* qb.select('*').limit(10, 20); // 10 results starting from offset 20
|
|
608
627
|
* ```
|
|
609
628
|
*/
|
|
610
|
-
limit(limit?: number, offset?: number): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields>;
|
|
629
|
+
limit(limit?: number, offset?: number): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields, CTEs>;
|
|
611
630
|
/**
|
|
612
631
|
* Sets an OFFSET clause to skip a number of results.
|
|
613
632
|
*
|
|
@@ -616,7 +635,7 @@ export declare class QueryBuilder<Entity extends object = AnyEntity, RootAlias e
|
|
|
616
635
|
* qb.select('*').limit(10).offset(20); // Results 21-30
|
|
617
636
|
* ```
|
|
618
637
|
*/
|
|
619
|
-
offset(offset?: number): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields>;
|
|
638
|
+
offset(offset?: number): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields, CTEs>;
|
|
620
639
|
withSchema(schema?: string): this;
|
|
621
640
|
setLockMode(mode?: LockMode, tables?: string[]): this;
|
|
622
641
|
setFlushMode(flushMode?: FlushMode): this;
|
|
@@ -646,13 +665,19 @@ export declare class QueryBuilder<Entity extends object = AnyEntity, RootAlias e
|
|
|
646
665
|
* Specifies FROM which entity's table select/update/delete will be executed, removing all previously set FROM-s.
|
|
647
666
|
* Allows setting a main string alias of the selection data.
|
|
648
667
|
*/
|
|
649
|
-
from<Entity extends object>(target: QueryBuilder<Entity>, aliasName?: string): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields>;
|
|
668
|
+
from<Entity extends object>(target: QueryBuilder<Entity>, aliasName?: string): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields, CTEs>;
|
|
650
669
|
/**
|
|
651
670
|
* Specifies FROM which entity's table select/update/delete will be executed, removing all previously set FROM-s.
|
|
652
671
|
* Allows setting a main string alias of the selection data.
|
|
653
672
|
*/
|
|
654
|
-
from<Entity extends object>(target: EntityName<Entity>): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields>;
|
|
673
|
+
from<Entity extends object>(target: EntityName<Entity>): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields, CTEs>;
|
|
674
|
+
/**
|
|
675
|
+
* Specifies a CTE name as the FROM source, with full type safety.
|
|
676
|
+
* The entity type is inferred from the CTE definition passed to `.with()`.
|
|
677
|
+
*/
|
|
678
|
+
from<Name extends string & keyof CTEs, Alias extends string = Name>(target: Name, aliasName?: Alias): SelectQueryBuilder<CTEs[Name], Alias, never, never, never, '*', CTEs>;
|
|
655
679
|
getNativeQuery(processVirtualEntity?: boolean): NativeQueryBuilder;
|
|
680
|
+
protected processReturningStatement(qb: NativeQueryBuilder, meta?: EntityMetadata, data?: Dictionary, returning?: Field<any>[]): void;
|
|
656
681
|
/**
|
|
657
682
|
* Returns the query with parameters as wildcards.
|
|
658
683
|
*/
|
|
@@ -750,7 +775,80 @@ export declare class QueryBuilder<Entity extends object = AnyEntity, RootAlias e
|
|
|
750
775
|
* 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.
|
|
751
776
|
*/
|
|
752
777
|
as<T>(targetEntity: EntityName<T>, alias: EntityKey<T>): NativeQueryBuilder;
|
|
753
|
-
|
|
778
|
+
/**
|
|
779
|
+
* Combines the current query with one or more other queries using `UNION ALL`.
|
|
780
|
+
* All queries must select the same columns. Returns a `QueryBuilder` that
|
|
781
|
+
* can be used with `$in`, passed to `qb.from()`, or converted via `.getQuery()`,
|
|
782
|
+
* `.getParams()`, `.toQuery()`, `.toRaw()`, etc.
|
|
783
|
+
*
|
|
784
|
+
* ```ts
|
|
785
|
+
* const qb1 = em.createQueryBuilder(Employee).select('id').where(condition1);
|
|
786
|
+
* const qb2 = em.createQueryBuilder(Employee).select('id').where(condition2);
|
|
787
|
+
* const qb3 = em.createQueryBuilder(Employee).select('id').where(condition3);
|
|
788
|
+
* const subquery = qb1.unionAll(qb2, qb3);
|
|
789
|
+
*
|
|
790
|
+
* const results = await em.find(Employee, { id: { $in: subquery } });
|
|
791
|
+
* ```
|
|
792
|
+
*/
|
|
793
|
+
unionAll(...others: (QueryBuilder<any> | NativeQueryBuilder)[]): QueryBuilder<Entity>;
|
|
794
|
+
/**
|
|
795
|
+
* Combines the current query with one or more other queries using `UNION` (with deduplication).
|
|
796
|
+
* All queries must select the same columns. Returns a `QueryBuilder` that
|
|
797
|
+
* can be used with `$in`, passed to `qb.from()`, or converted via `.getQuery()`,
|
|
798
|
+
* `.getParams()`, `.toQuery()`, `.toRaw()`, etc.
|
|
799
|
+
*
|
|
800
|
+
* ```ts
|
|
801
|
+
* const qb1 = em.createQueryBuilder(Employee).select('id').where(condition1);
|
|
802
|
+
* const qb2 = em.createQueryBuilder(Employee).select('id').where(condition2);
|
|
803
|
+
* const subquery = qb1.union(qb2);
|
|
804
|
+
*
|
|
805
|
+
* const results = await em.find(Employee, { id: { $in: subquery } });
|
|
806
|
+
* ```
|
|
807
|
+
*/
|
|
808
|
+
union(...others: (QueryBuilder<any> | NativeQueryBuilder)[]): QueryBuilder<Entity>;
|
|
809
|
+
private buildUnionQuery;
|
|
810
|
+
/**
|
|
811
|
+
* Adds a Common Table Expression (CTE) to the query.
|
|
812
|
+
* When a `QueryBuilder` is passed, its entity type is tracked for type-safe `from()`.
|
|
813
|
+
*
|
|
814
|
+
* @example
|
|
815
|
+
* ```ts
|
|
816
|
+
* const recentBooks = em.createQueryBuilder(Book, 'b').select('*').where({ ... });
|
|
817
|
+
* const qb = em.createQueryBuilder(Author, 'a')
|
|
818
|
+
* .with('recent_books', recentBooks)
|
|
819
|
+
* .select('*')
|
|
820
|
+
* .from('recent_books', 'rb'); // entity type inferred as Book
|
|
821
|
+
* ```
|
|
822
|
+
*/
|
|
823
|
+
with<Name extends string, Q extends QueryBuilder<any>>(name: Name, query: Q, options?: CteOptions): QueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields, CTEs & Record<Name, Q extends QueryBuilder<infer T> ? T : object>>;
|
|
824
|
+
/**
|
|
825
|
+
* Adds a Common Table Expression (CTE) to the query using a `NativeQueryBuilder` or raw SQL fragment.
|
|
826
|
+
* The CTE name is tracked but without entity type inference — use `from()` to query from it.
|
|
827
|
+
*/
|
|
828
|
+
with<Name extends string>(name: Name, query: NativeQueryBuilder | RawQueryFragment, options?: CteOptions): QueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields, CTEs & Record<Name, object>>;
|
|
829
|
+
/**
|
|
830
|
+
* Adds a recursive Common Table Expression (CTE) to the query.
|
|
831
|
+
* When a `QueryBuilder` is passed, its entity type is tracked for type-safe `from()`.
|
|
832
|
+
*
|
|
833
|
+
* @example
|
|
834
|
+
* ```ts
|
|
835
|
+
* const base = em.createQueryBuilder(Category).select('*').where({ parent: null });
|
|
836
|
+
* const rec = em.createQueryBuilder(Category, 'c').select('c.*')
|
|
837
|
+
* .leftJoin('c.parent', 'ct', { id: sql.ref('c.parentId') });
|
|
838
|
+
* const qb = em.createQueryBuilder(Category)
|
|
839
|
+
* .withRecursive('category_tree', base.unionAll(rec))
|
|
840
|
+
* .select('*')
|
|
841
|
+
* .from('category_tree', 'ct'); // entity type inferred as Category
|
|
842
|
+
* ```
|
|
843
|
+
*/
|
|
844
|
+
withRecursive<Name extends string, Q extends QueryBuilder<any>>(name: Name, query: Q, options?: CteOptions): QueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields, CTEs & Record<Name, Q extends QueryBuilder<infer T> ? T : object>>;
|
|
845
|
+
/**
|
|
846
|
+
* Adds a recursive Common Table Expression (CTE) to the query using a `NativeQueryBuilder` or raw SQL fragment.
|
|
847
|
+
* The CTE name is tracked but without entity type inference — use `from()` to query from it.
|
|
848
|
+
*/
|
|
849
|
+
withRecursive<Name extends string>(name: Name, query: NativeQueryBuilder | RawQueryFragment, options?: CteOptions): QueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields, CTEs & Record<Name, object>>;
|
|
850
|
+
private addCte;
|
|
851
|
+
clone(reset?: boolean | (keyof QBState<Entity>)[], preserve?: (keyof QBState<Entity>)[]): QueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields, CTEs>;
|
|
754
852
|
/**
|
|
755
853
|
* Sets logger context for this query builder.
|
|
756
854
|
*/
|
|
@@ -775,7 +873,7 @@ export declare class QueryBuilder<Entity extends object = AnyEntity, RootAlias e
|
|
|
775
873
|
* For embeddeds: navigates into flattened embeddeds to return the correct field name.
|
|
776
874
|
*/
|
|
777
875
|
protected resolveNestedPath(field: string): string | string[];
|
|
778
|
-
|
|
876
|
+
protected init(type: QueryType, data?: any, cond?: any): this;
|
|
779
877
|
private getQueryBase;
|
|
780
878
|
private applyDiscriminatorCondition;
|
|
781
879
|
/**
|
|
@@ -836,10 +934,11 @@ export declare class QueryBuilder<Entity extends object = AnyEntity, RootAlias e
|
|
|
836
934
|
private wrapModifySubQuery;
|
|
837
935
|
private getSchema;
|
|
838
936
|
/** @internal */
|
|
839
|
-
createAlias<U = unknown>(entityName: EntityName<U>, aliasName: string, subQuery?: NativeQueryBuilder): Alias<U>;
|
|
937
|
+
createAlias<U = unknown>(entityName: EntityName<U>, aliasName: string, subQuery?: NativeQueryBuilder | RawQueryFragment): Alias<U>;
|
|
840
938
|
private createMainAlias;
|
|
841
939
|
private fromSubQuery;
|
|
842
940
|
private fromEntityName;
|
|
941
|
+
private fromRawTable;
|
|
843
942
|
private createQueryBuilderHelper;
|
|
844
943
|
private ensureFromClause;
|
|
845
944
|
private ensureNotFinalized;
|
|
@@ -867,14 +966,14 @@ type PopulatedDTO<T, K extends keyof T> = NonNullable<T[K]> extends Collection<i
|
|
|
867
966
|
type SubFields<F extends string, Rel extends string> = F extends `${Rel}.${infer Sub}` ? Sub : never;
|
|
868
967
|
type RootFields<F extends string, H extends string> = F extends `${string}.${string}` ? F extends `${H}.${string}` ? never : F : F;
|
|
869
968
|
type JoinDTO<T, K extends keyof T, F extends string> = NonNullable<T[K]> extends Collection<infer U> ? SubFields<F, K & string> extends never ? EntityDTOProp<T, Collection<U>> : DirectDTO<U, (SubFields<F, K & string> | PrimaryProperty<U>) & keyof U>[] : SubFields<F, K & string> extends never ? EntityDTOProp<T, T[K]> : DirectDTO<NonNullable<T[K]>, (SubFields<F, K & string> | PrimaryProperty<NonNullable<T[K]>>) & keyof NonNullable<T[K]>> | Extract<T[K], null | undefined>;
|
|
870
|
-
type ExecuteDTO<T, H extends string, F extends string> = [
|
|
871
|
-
H
|
|
872
|
-
] extends [never] ? [F] extends ['*'] ? EntityDTOFlat<T> : DirectDTO<T, F & keyof T> : [F] extends ['*'] ? true extends (H extends `${string}.${string}` ? true : false) ? SerializeDTO<T, H> : Omit<EntityDTOFlat<T>, H & keyof EntityDTOFlat<T>> & {
|
|
969
|
+
type ExecuteDTO<T, H extends string, F extends string> = [H] extends [never] ? [F] extends ['*'] ? EntityDTOFlat<T> : DirectDTO<T, F & keyof T> : [F] extends ['*'] ? true extends (H extends `${string}.${string}` ? true : false) ? SerializeDTO<T, H> : Omit<EntityDTOFlat<T>, H & keyof EntityDTOFlat<T>> & {
|
|
873
970
|
[K in H & keyof T as K & keyof EntityDTOFlat<T>]: PopulatedDTO<T, K> | Extract<T[K], null | undefined>;
|
|
874
971
|
} : true extends (H extends `${string}.${string}` ? true : false) ? EntityDTOFlat<Loaded<T, H, F>> : DirectDTO<T, (RootFields<F, H> | PrimaryProperty<T>) & keyof T> & {
|
|
875
972
|
[K in H & keyof T]: JoinDTO<T, K, F>;
|
|
876
973
|
};
|
|
877
|
-
|
|
974
|
+
/** Shorthand for `QueryBuilder` with all generic parameters set to `any`. */
|
|
975
|
+
export type AnyQueryBuilder<T extends object = AnyEntity> = QueryBuilder<T, any, any, any, any, any, any>;
|
|
976
|
+
export interface SelectQueryBuilder<Entity extends object = AnyEntity, RootAlias extends string = never, Hint extends string = never, Context extends object = never, RawAliases extends string = never, Fields extends string = '*', CTEs extends Record<string, object> = {}> extends QueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields, CTEs> {
|
|
878
977
|
execute<Result = ExecuteDTO<Entity, Hint, Fields>[]>(method?: 'all' | 'get' | 'run', mapResults?: boolean): Promise<Result>;
|
|
879
978
|
execute<Result = ExecuteDTO<Entity, Hint, Fields>[]>(method: 'all', mapResults?: boolean): Promise<Result>;
|
|
880
979
|
execute<Result = ExecuteDTO<Entity, Hint, Fields>>(method: 'get', mapResults?: boolean): Promise<Result>;
|