@mikro-orm/sql 7.0.0-dev.215 → 7.0.0-dev.217
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/AbstractSqlDriver.d.ts +9 -9
- package/AbstractSqlDriver.js +61 -57
- package/AbstractSqlPlatform.d.ts +3 -3
- package/SqlEntityManager.d.ts +1 -1
- package/dialects/postgresql/BasePostgreSqlPlatform.d.ts +2 -2
- package/package.json +2 -2
- package/query/CriteriaNode.d.ts +1 -0
- package/query/CriteriaNode.js +2 -0
- package/query/CriteriaNodeFactory.d.ts +5 -5
- package/query/CriteriaNodeFactory.js +17 -17
- package/query/NativeQueryBuilder.d.ts +3 -2
- package/query/ObjectCriteriaNode.js +5 -0
- package/query/QueryBuilder.d.ts +477 -64
- package/query/QueryBuilder.js +225 -29
- package/query/QueryBuilderHelper.d.ts +7 -7
- package/query/QueryBuilderHelper.js +3 -10
- package/query/raw.d.ts +11 -3
- package/query/raw.js +1 -2
- package/tsconfig.build.tsbuildinfo +1 -1
- package/typings.d.ts +17 -19
package/query/QueryBuilder.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { type AnyEntity, type ConnectionType, type Dictionary, type EntityData, type EntityKey, type EntityManager, type EntityMetadata, type EntityName, type EntityProperty, type ExpandProperty, type FilterOptions, type FlushMode, type GroupOperator, type Loaded, LockMode, type LoggingOptions, type MetadataStorage, type ObjectQuery, PopulateHint, type PopulateOptions, type
|
|
1
|
+
import { type AnyEntity, type AutoPath, type ConnectionType, type Dictionary, type EntityData, type EntityKey, type EntityManager, type EntityMetadata, type EntityName, type EntityProperty, type ExpandProperty, type FilterOptions, type FilterValue, type FlushMode, type GroupOperator, type Loaded, LockMode, type LoggingOptions, type MetadataStorage, type ObjectQuery, PopulateHint, type PopulateOptions, type PopulatePath, QueryFlag, type QueryOrderKeysFlat, type QueryOrderMap, type QueryResult, RawQueryFragment, type Raw, type RequiredEntityData, type Scalar, 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
|
-
import type {
|
|
6
|
+
import type { ICriteriaNodeProcessOptions, InternalField, JoinOptions } from '../typings.js';
|
|
7
7
|
import type { AbstractSqlPlatform } from '../AbstractSqlPlatform.js';
|
|
8
8
|
import { NativeQueryBuilder } from './NativeQueryBuilder.js';
|
|
9
9
|
export interface ExecuteOptions {
|
|
@@ -34,26 +34,101 @@ export interface QBStreamOptions {
|
|
|
34
34
|
*/
|
|
35
35
|
rawResults?: boolean;
|
|
36
36
|
}
|
|
37
|
-
type AnyString = string & {};
|
|
38
|
-
type Compute<T> = {
|
|
39
|
-
[K in keyof T]: T[K];
|
|
40
|
-
} & {};
|
|
41
37
|
type IsNever<T, True = true, False = false> = [T] extends [never] ? True : False;
|
|
42
38
|
type GetAlias<T extends string> = T extends `${infer A}.${string}` ? A : never;
|
|
43
39
|
type GetPropName<T extends string> = T extends `${string}.${infer P}` ? P : T;
|
|
44
40
|
type AppendToHint<Parent extends string, Child extends string> = `${Parent}.${Child}`;
|
|
41
|
+
/**
|
|
42
|
+
* Context tuple format: [Path, Alias, Type, Select]
|
|
43
|
+
* - Path: The relation path from root entity (e.g., 'books', 'books.author')
|
|
44
|
+
* - Alias: The SQL alias used in the query (e.g., 'b', 'a1')
|
|
45
|
+
* - Type: The entity type of the joined relation
|
|
46
|
+
* - Select: Whether this join was created via joinAndSelect (affects Fields tracking)
|
|
47
|
+
*
|
|
48
|
+
* Example: After `qb.leftJoin('a.books', 'b')`, Context becomes:
|
|
49
|
+
* { b: ['books', 'b', Book, false] }
|
|
50
|
+
*/
|
|
45
51
|
type AddToContext<Type extends object, Context, Field extends string, Alias extends string, Select extends boolean> = {
|
|
46
52
|
[K in Alias]: [GetPath<Context, Field>, K, ExpandProperty<Type[GetPropName<Field> & keyof Type]>, Select];
|
|
47
53
|
};
|
|
48
54
|
type GetPath<Context, Field extends string> = GetAlias<Field> extends infer Alias ? IsNever<Alias> extends true ? GetPropName<Field> : Alias extends keyof Context ? Context[Alias] extends [infer Path, ...any[]] ? AppendToHint<Path & string, GetPropName<Field>> : GetPropName<Field> : GetPropName<Field> : GetPropName<Field>;
|
|
49
|
-
type GetType<Type extends object, Context, Field extends string> = GetAlias<Field> extends infer Alias ? IsNever<Alias> extends true ? Type : Alias extends keyof Context ? Context[Alias] extends [string, string, infer PropType] ? PropType & object : Type : Type : Type;
|
|
55
|
+
type GetType<Type extends object, Context, Field extends string> = GetAlias<Field> extends infer Alias ? IsNever<Alias> extends true ? Type : Alias extends keyof Context ? Context[Alias] extends [string, string, infer PropType, any] ? PropType & object : Type : Type : Type;
|
|
50
56
|
type AddToHint<RootAlias, Context, Field extends string, Select extends boolean = false> = Select extends true ? GetAlias<Field> extends infer Alias ? IsNever<Alias> extends true ? GetPropName<Field> : Alias extends RootAlias ? GetPropName<Field> : Alias extends keyof Context ? Context[Alias] extends [infer Path, ...any[]] ? AppendToHint<Path & string, GetPropName<Field>> : GetPropName<Field> : GetPropName<Field> : GetPropName<Field> : never;
|
|
51
57
|
export type ModifyHint<RootAlias, Context, Hint extends string, Field extends string, Select extends boolean = false> = Hint | AddToHint<RootAlias, Context, Field, Select>;
|
|
52
|
-
export type ModifyContext<Entity extends object, Context, Field extends string, Alias extends string, Select extends boolean = false> =
|
|
58
|
+
export type ModifyContext<Entity extends object, Context, Field extends string, Alias extends string, Select extends boolean = false> = IsNever<Context> extends true ? AddToContext<GetType<Entity, object, Field>, object, Field, Alias, Select> : Context & AddToContext<GetType<Entity, Context, Field>, Context, Field, Alias, Select>;
|
|
59
|
+
type StripRootAlias<F extends string, RootAlias extends string, Context = never> = F extends `${RootAlias}.${infer Field}` ? Field : F extends `${infer Alias}.${string}` ? Alias extends AliasNames<Context> ? never : F : F;
|
|
60
|
+
type ExtractRootFields<Fields, RootAlias extends string, Context = never> = [Fields] extends ['*'] ? '*' : Fields extends `${RootAlias}.*` ? '*' : Fields extends string ? StripRootAlias<Fields, RootAlias, Context> : never;
|
|
61
|
+
type PrefixWithPath<Path extends string, Field extends string> = `${Path}.${Field}`;
|
|
62
|
+
type StripJoinAlias<F extends string, Alias extends string> = F extends `${Alias}.${infer Field}` ? Field : F;
|
|
63
|
+
type AddJoinFields<RootAlias, Context, Field extends string, Alias extends string, JoinFields extends readonly string[]> = JoinFields extends readonly (infer F)[] ? F extends string ? PrefixWithPath<AddToHint<RootAlias, Context, Field, true> & string, StripJoinAlias<F, Alias>> : never : never;
|
|
64
|
+
export type ModifyFields<CurrentFields extends string, RootAlias, Context, Field extends string, Alias extends string, JoinFields extends readonly string[] | undefined> = JoinFields extends readonly string[] ? CurrentFields | AddJoinFields<RootAlias, Context, Field, Alias, JoinFields> : CurrentFields;
|
|
53
65
|
type EntityRelations<T> = EntityKey<T, true>;
|
|
54
|
-
type
|
|
55
|
-
|
|
56
|
-
type
|
|
66
|
+
type JoinedEntityType<Entity extends object, Context, Field extends string> = ExpandProperty<GetType<Entity, Context, Field>[GetPropName<Field> & keyof GetType<Entity, Context, Field>]>;
|
|
67
|
+
type AliasNames<Context> = Context[keyof Context] extends infer Join ? Join extends any ? Join extends [string, infer Alias, any, any] ? Alias & string : never : never : never;
|
|
68
|
+
type ContextRelationKeys<Context> = Context[keyof Context] extends infer Join ? Join extends any ? Join extends [string, infer Alias, infer Type, any] ? `${Alias & string}.${EntityRelations<Type & object>}` : never : never : never;
|
|
69
|
+
export type QBField<Entity, RootAlias extends string, Context> = EntityRelations<Entity> | `${RootAlias}.${EntityRelations<Entity>}` | ([Context] extends [never] ? never : ContextRelationKeys<Context>);
|
|
70
|
+
type ContextFieldKeys<Context> = Context[keyof Context] extends infer Join ? Join extends any ? Join extends [string, infer Alias, infer Type, any] ? `${Alias & string}.${keyof Type & string}` : never : never : never;
|
|
71
|
+
export type Field<Entity, RootAlias extends string = never, Context = never> = EntityKey<Entity> | (IsNever<RootAlias> extends true ? never : `${RootAlias}.${EntityKey<Entity>}` | `${RootAlias}.*`) | ([Context] extends [never] ? never : ContextFieldKeys<Context> | `${AliasNames<Context>}.*`) | '*' | QueryBuilder<any> | NativeQueryBuilder | RawQueryFragment<any> | (RawQueryFragment & symbol);
|
|
72
|
+
type RootAliasOrderKeys<RootAlias extends string, Entity> = {
|
|
73
|
+
[K in `${RootAlias}.${EntityKey<Entity>}`]?: QueryOrderKeysFlat;
|
|
74
|
+
};
|
|
75
|
+
type ContextOrderKeys<Context> = {
|
|
76
|
+
[K in ContextFieldKeys<Context>]?: QueryOrderKeysFlat;
|
|
77
|
+
};
|
|
78
|
+
export type ContextOrderByMap<Entity, RootAlias extends string = never, Context = never> = QueryOrderMap<Entity> | ((IsNever<RootAlias> extends true ? {} : RootAliasOrderKeys<RootAlias, Entity>) & ([Context] extends [never] ? {} : ContextOrderKeys<Context>));
|
|
79
|
+
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;
|
|
80
|
+
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;
|
|
81
|
+
type NestedAutoPath<Entity, RootAlias extends string, Context, P extends string> = P extends `${string}:ref` ? never : AliasedPath<RootAlias, Entity, P> | ContextAliasedPath<Context, P> | AutoPath<Entity, P, `${PopulatePath.ALL}`>;
|
|
82
|
+
type AliasedObjectQuery<Entity extends object, Alias extends string> = {
|
|
83
|
+
[K in EntityKey<Entity> as `${Alias}.${K}`]?: ObjectQuery<Entity>[K];
|
|
84
|
+
};
|
|
85
|
+
type JoinCondition<JoinedEntity extends object, Alias extends string> = ObjectQuery<JoinedEntity> | AliasedObjectQuery<JoinedEntity, Alias>;
|
|
86
|
+
type RawJoinCondition = {
|
|
87
|
+
[key: string]: FilterValue<Scalar> | RawQueryFragment;
|
|
88
|
+
};
|
|
89
|
+
type ExtractRawAliasFromField<F> = F extends RawQueryFragment<infer A> ? (A extends string ? A : never) : never;
|
|
90
|
+
type ExtractRawAliasesFromTuple<T extends readonly unknown[]> = T extends readonly [infer Head, ...infer Tail] ? ExtractRawAliasFromField<Head> | ExtractRawAliasesFromTuple<Tail> : never;
|
|
91
|
+
type ExtractRawAliases<Fields> = Fields extends readonly unknown[] ? ExtractRawAliasesFromTuple<Fields> : ExtractRawAliasFromField<Fields>;
|
|
92
|
+
type FlatOperatorMap = {
|
|
93
|
+
$eq?: Scalar | readonly Scalar[] | Subquery | null;
|
|
94
|
+
$ne?: Scalar | readonly Scalar[] | Subquery | null;
|
|
95
|
+
$in?: readonly Scalar[] | Raw | Subquery;
|
|
96
|
+
$nin?: readonly Scalar[] | Raw | Subquery;
|
|
97
|
+
$gt?: Scalar | Subquery;
|
|
98
|
+
$gte?: Scalar | Subquery;
|
|
99
|
+
$lt?: Scalar | Subquery;
|
|
100
|
+
$lte?: Scalar | Subquery;
|
|
101
|
+
$like?: string;
|
|
102
|
+
$re?: string;
|
|
103
|
+
$ilike?: string;
|
|
104
|
+
$fulltext?: string;
|
|
105
|
+
$overlap?: readonly string[] | string | object;
|
|
106
|
+
$contains?: readonly string[] | string | object;
|
|
107
|
+
$contained?: readonly string[] | string | object;
|
|
108
|
+
$exists?: boolean;
|
|
109
|
+
$hasKey?: string;
|
|
110
|
+
$hasKeys?: readonly string[];
|
|
111
|
+
$hasSomeKeys?: readonly string[];
|
|
112
|
+
};
|
|
113
|
+
type AliasedFilterValue = Scalar | FlatOperatorMap | readonly Scalar[] | null | QueryBuilder<any> | NativeQueryBuilder;
|
|
114
|
+
type TypedAliasedFilterValue<T> = FilterValue<ExpandProperty<T>> | QueryBuilder<any> | NativeQueryBuilder;
|
|
115
|
+
type RootAliasFilterKeys<RootAlias extends string, Entity> = {
|
|
116
|
+
[K in EntityKey<Entity> as `${RootAlias}.${K}`]?: TypedAliasedFilterValue<Entity[K]>;
|
|
117
|
+
};
|
|
118
|
+
type ContextFilterKeys<Context> = {
|
|
119
|
+
[K in ContextFieldKeys<Context>]?: AliasedFilterValue;
|
|
120
|
+
};
|
|
121
|
+
type RawFilterKeys<RawAliases extends string> = {
|
|
122
|
+
[K in RawAliases]?: AliasedFilterValue;
|
|
123
|
+
};
|
|
124
|
+
type NestedFilterCondition<Entity, RootAlias extends string, Context, RawAliases extends string> = ObjectQuery<Entity> | ((IsNever<RootAlias> extends true ? {} : RootAliasFilterKeys<RootAlias, Entity>) & ([Context] extends [never] ? {} : ContextFilterKeys<Context>) & (IsNever<RawAliases> extends true ? {} : RawFilterKeys<RawAliases>));
|
|
125
|
+
type GroupOperators<RootAlias extends string, Context, Entity, RawAliases extends string> = {
|
|
126
|
+
$and?: NestedFilterCondition<Entity, RootAlias, Context, RawAliases>[];
|
|
127
|
+
$or?: NestedFilterCondition<Entity, RootAlias, Context, RawAliases>[];
|
|
128
|
+
$not?: NestedFilterCondition<Entity, RootAlias, Context, RawAliases>;
|
|
129
|
+
};
|
|
130
|
+
export type AliasedFilterCondition<RootAlias extends string, Context, Entity, RawAliases extends string = never> = (IsNever<RootAlias> extends true ? {} : RootAliasFilterKeys<RootAlias, Entity>) & ([Context] extends [never] ? {} : ContextFilterKeys<Context>) & (IsNever<RawAliases> extends true ? {} : RawFilterKeys<RawAliases>) & GroupOperators<RootAlias, Context, Entity, RawAliases>;
|
|
131
|
+
export type QBFilterQuery<Entity, RootAlias extends string = never, Context = never, RawAliases extends string = never> = ObjectQuery<Entity> | AliasedFilterCondition<RootAlias, Context, Entity, RawAliases>;
|
|
57
132
|
/**
|
|
58
133
|
* SQL query builder with fluent interface.
|
|
59
134
|
*
|
|
@@ -73,13 +148,14 @@ type EntityKeyOrString<Entity extends object = AnyEntity> = AnyString | keyof En
|
|
|
73
148
|
* const publisher = await qb.getSingleResult();
|
|
74
149
|
* ```
|
|
75
150
|
*/
|
|
76
|
-
export declare class QueryBuilder<Entity extends object = AnyEntity, RootAlias extends string = never, Hint extends string = never, Context extends object = never> {
|
|
151
|
+
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 {
|
|
77
152
|
protected readonly metadata: MetadataStorage;
|
|
78
153
|
protected readonly driver: AbstractSqlDriver;
|
|
79
154
|
protected readonly context?: Transaction | undefined;
|
|
80
155
|
protected connectionType?: ConnectionType | undefined;
|
|
81
156
|
protected em?: SqlEntityManager | undefined;
|
|
82
157
|
protected loggerContext?: (LoggingOptions & Dictionary) | undefined;
|
|
158
|
+
readonly __subquery: true;
|
|
83
159
|
get mainAlias(): Alias<Entity>;
|
|
84
160
|
get alias(): string;
|
|
85
161
|
get helper(): QueryBuilderHelper;
|
|
@@ -87,7 +163,7 @@ export declare class QueryBuilder<Entity extends object = AnyEntity, RootAlias e
|
|
|
87
163
|
/** @internal */
|
|
88
164
|
_type?: QueryType;
|
|
89
165
|
/** @internal */
|
|
90
|
-
_fields?:
|
|
166
|
+
_fields?: InternalField<Entity>[];
|
|
91
167
|
/** @internal */
|
|
92
168
|
_populate: PopulateOptions<Entity>[];
|
|
93
169
|
/** @internal */
|
|
@@ -108,9 +184,9 @@ export declare class QueryBuilder<Entity extends object = AnyEntity, RootAlias e
|
|
|
108
184
|
protected _cond: Dictionary;
|
|
109
185
|
protected _data: Dictionary;
|
|
110
186
|
protected _orderBy: QueryOrderMap<Entity>[];
|
|
111
|
-
protected _groupBy:
|
|
187
|
+
protected _groupBy: InternalField<Entity>[];
|
|
112
188
|
protected _having: Dictionary;
|
|
113
|
-
protected _returning?:
|
|
189
|
+
protected _returning?: InternalField<Entity>[];
|
|
114
190
|
protected _onConflict?: OnConflictClause<Entity>[];
|
|
115
191
|
protected _limit?: number;
|
|
116
192
|
protected _offset?: number;
|
|
@@ -137,27 +213,192 @@ export declare class QueryBuilder<Entity extends object = AnyEntity, RootAlias e
|
|
|
137
213
|
* @internal
|
|
138
214
|
*/
|
|
139
215
|
constructor(entityName: EntityName<Entity> | QueryBuilder<Entity, any, any, any>, metadata: MetadataStorage, driver: AbstractSqlDriver, context?: Transaction | undefined, alias?: string, connectionType?: ConnectionType | undefined, em?: SqlEntityManager | undefined, loggerContext?: (LoggingOptions & Dictionary) | undefined);
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
216
|
+
/**
|
|
217
|
+
* Creates a SELECT query, specifying the fields to retrieve.
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* ```ts
|
|
221
|
+
* // Select specific fields
|
|
222
|
+
* const qb = em.createQueryBuilder(User, 'u');
|
|
223
|
+
* qb.select(['u.id', 'u.name', 'u.email']);
|
|
224
|
+
*
|
|
225
|
+
* // Select with raw expressions
|
|
226
|
+
* qb.select([raw('count(*) as total')]);
|
|
227
|
+
*
|
|
228
|
+
* // Select with distinct
|
|
229
|
+
* qb.select('*', true);
|
|
230
|
+
* ```
|
|
231
|
+
*/
|
|
232
|
+
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>>;
|
|
233
|
+
/**
|
|
234
|
+
* Creates a SELECT query, specifying the fields to retrieve.
|
|
235
|
+
*
|
|
236
|
+
* @example
|
|
237
|
+
* ```ts
|
|
238
|
+
* // Select specific fields
|
|
239
|
+
* const qb = em.createQueryBuilder(User, 'u');
|
|
240
|
+
* qb.select(['u.id', 'u.name', 'u.email']);
|
|
241
|
+
*
|
|
242
|
+
* // Select with raw expressions
|
|
243
|
+
* qb.select([raw('count(*) as total')]);
|
|
244
|
+
*
|
|
245
|
+
* // Select with distinct
|
|
246
|
+
* qb.select('*', true);
|
|
247
|
+
* ```
|
|
248
|
+
*/
|
|
249
|
+
select<const P extends string>(fields: readonly NestedAutoPath<Entity, RootAlias, Context, P>[], distinct?: boolean): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, ExtractRootFields<P, RootAlias, Context>>;
|
|
250
|
+
/**
|
|
251
|
+
* Creates a SELECT query, specifying the fields to retrieve.
|
|
252
|
+
*
|
|
253
|
+
* @example
|
|
254
|
+
* ```ts
|
|
255
|
+
* // Select specific fields with nested paths (e.g., for embedded properties)
|
|
256
|
+
* const qb = em.createQueryBuilder(User, 'u');
|
|
257
|
+
* qb.select('address.city');
|
|
258
|
+
* ```
|
|
259
|
+
*/
|
|
260
|
+
select<const P extends string>(fields: NestedAutoPath<Entity, RootAlias, Context, P>, distinct?: boolean): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, ExtractRootFields<P, RootAlias, Context>>;
|
|
261
|
+
/**
|
|
262
|
+
* Creates a SELECT query, specifying the fields to retrieve.
|
|
263
|
+
*
|
|
264
|
+
* @example
|
|
265
|
+
* ```ts
|
|
266
|
+
* // Select specific fields
|
|
267
|
+
* const qb = em.createQueryBuilder(User, 'u');
|
|
268
|
+
* qb.select(['u.id', 'u.name', 'u.email']);
|
|
269
|
+
*
|
|
270
|
+
* // Select with raw expressions
|
|
271
|
+
* qb.select([raw('count(*) as total')]);
|
|
272
|
+
*
|
|
273
|
+
* // Select with distinct
|
|
274
|
+
* qb.select('*', true);
|
|
275
|
+
* ```
|
|
276
|
+
*/
|
|
277
|
+
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>>;
|
|
278
|
+
/**
|
|
279
|
+
* Adds fields to an existing SELECT query.
|
|
280
|
+
*/
|
|
281
|
+
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>>;
|
|
282
|
+
distinct(): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields>;
|
|
283
|
+
/** postgres only */
|
|
284
|
+
distinctOn<const F extends readonly Field<Entity, RootAlias, Context>[]>(fields: F): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields>;
|
|
143
285
|
/** postgres only */
|
|
144
|
-
distinctOn
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
286
|
+
distinctOn<F extends Field<Entity, RootAlias, Context>>(fields: F): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields>;
|
|
287
|
+
/**
|
|
288
|
+
* Creates an INSERT query with the given data.
|
|
289
|
+
*
|
|
290
|
+
* @example
|
|
291
|
+
* ```ts
|
|
292
|
+
* await em.createQueryBuilder(User)
|
|
293
|
+
* .insert({ name: 'John', email: 'john@example.com' })
|
|
294
|
+
* .execute();
|
|
295
|
+
*
|
|
296
|
+
* // Bulk insert
|
|
297
|
+
* await em.createQueryBuilder(User)
|
|
298
|
+
* .insert([{ name: 'John' }, { name: 'Jane' }])
|
|
299
|
+
* .execute();
|
|
300
|
+
* ```
|
|
301
|
+
*/
|
|
302
|
+
insert(data: RequiredEntityData<Entity> | RequiredEntityData<Entity>[]): InsertQueryBuilder<Entity, RootAlias, Context>;
|
|
303
|
+
/**
|
|
304
|
+
* Creates an UPDATE query with the given data.
|
|
305
|
+
* Use `where()` to specify which rows to update.
|
|
306
|
+
*
|
|
307
|
+
* @example
|
|
308
|
+
* ```ts
|
|
309
|
+
* await em.createQueryBuilder(User)
|
|
310
|
+
* .update({ name: 'John Doe' })
|
|
311
|
+
* .where({ id: 1 })
|
|
312
|
+
* .execute();
|
|
313
|
+
* ```
|
|
314
|
+
*/
|
|
315
|
+
update(data: EntityData<Entity>): UpdateQueryBuilder<Entity, RootAlias, Context>;
|
|
316
|
+
/**
|
|
317
|
+
* Creates a DELETE query.
|
|
318
|
+
* Use `where()` to specify which rows to delete.
|
|
319
|
+
*
|
|
320
|
+
* @example
|
|
321
|
+
* ```ts
|
|
322
|
+
* await em.createQueryBuilder(User)
|
|
323
|
+
* .delete()
|
|
324
|
+
* .where({ id: 1 })
|
|
325
|
+
* .execute();
|
|
326
|
+
*
|
|
327
|
+
* // Or pass the condition directly
|
|
328
|
+
* await em.createQueryBuilder(User)
|
|
329
|
+
* .delete({ isActive: false })
|
|
330
|
+
* .execute();
|
|
331
|
+
* ```
|
|
332
|
+
*/
|
|
333
|
+
delete(cond?: QBFilterQuery<Entity, RootAlias, Context, RawAliases>): DeleteQueryBuilder<Entity, RootAlias, Context>;
|
|
334
|
+
/**
|
|
335
|
+
* Creates a TRUNCATE query to remove all rows from the table.
|
|
336
|
+
*/
|
|
148
337
|
truncate(): TruncateQueryBuilder<Entity>;
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
338
|
+
/**
|
|
339
|
+
* Creates a COUNT query to count matching rows.
|
|
340
|
+
*
|
|
341
|
+
* @example
|
|
342
|
+
* ```ts
|
|
343
|
+
* const count = await em.createQueryBuilder(User)
|
|
344
|
+
* .count()
|
|
345
|
+
* .where({ isActive: true })
|
|
346
|
+
* .execute('get');
|
|
347
|
+
* ```
|
|
348
|
+
*/
|
|
349
|
+
count<F extends Field<Entity, RootAlias, Context>>(field?: F | F[], distinct?: boolean): CountQueryBuilder<Entity>;
|
|
350
|
+
/**
|
|
351
|
+
* Adds a JOIN clause to the query for an entity relation.
|
|
352
|
+
*
|
|
353
|
+
* @example
|
|
354
|
+
* ```ts
|
|
355
|
+
* const qb = em.createQueryBuilder(Book, 'b');
|
|
356
|
+
* qb.select('*')
|
|
357
|
+
* .join('b.author', 'a')
|
|
358
|
+
* .where({ 'a.name': 'John' });
|
|
359
|
+
* ```
|
|
360
|
+
*/
|
|
361
|
+
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>;
|
|
362
|
+
/**
|
|
363
|
+
* Adds a JOIN clause to the query for a subquery.
|
|
364
|
+
*/
|
|
365
|
+
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>;
|
|
366
|
+
/**
|
|
367
|
+
* Adds an INNER JOIN clause to the query for an entity relation.
|
|
368
|
+
*/
|
|
369
|
+
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>;
|
|
370
|
+
/**
|
|
371
|
+
* Adds an INNER JOIN clause to the query for a subquery.
|
|
372
|
+
*/
|
|
373
|
+
innerJoin<Alias extends string>(field: RawQueryFragment | QueryBuilder<any>, alias: Alias, cond?: RawJoinCondition, schema?: string): SelectQueryBuilder<Entity, RootAlias, Hint, ModifyContext<Entity, Context, string, Alias>, RawAliases>;
|
|
374
|
+
innerJoinLateral<Alias extends string>(field: RawQueryFragment | QueryBuilder<any>, alias: Alias, cond?: RawJoinCondition, schema?: string): SelectQueryBuilder<Entity, RootAlias, Hint, ModifyContext<Entity, Context, string, Alias>, RawAliases>;
|
|
375
|
+
/**
|
|
376
|
+
* Adds a LEFT JOIN clause to the query for an entity relation.
|
|
377
|
+
*/
|
|
378
|
+
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>;
|
|
379
|
+
/**
|
|
380
|
+
* Adds a LEFT JOIN clause to the query for a subquery.
|
|
381
|
+
*/
|
|
382
|
+
leftJoin<Alias extends string>(field: RawQueryFragment | QueryBuilder<any>, alias: Alias, cond?: RawJoinCondition, schema?: string): SelectQueryBuilder<Entity, RootAlias, Hint, ModifyContext<Entity, Context, string, Alias>, RawAliases>;
|
|
383
|
+
leftJoinLateral<Alias extends string>(field: RawQueryFragment | QueryBuilder<any>, alias: Alias, cond?: RawJoinCondition, schema?: string): SelectQueryBuilder<Entity, RootAlias, Hint, ModifyContext<Entity, Context, string, Alias>, RawAliases>;
|
|
384
|
+
/**
|
|
385
|
+
* Adds a JOIN clause and automatically selects the joined entity's fields.
|
|
386
|
+
* This is useful for eager loading related entities.
|
|
387
|
+
*
|
|
388
|
+
* @example
|
|
389
|
+
* ```ts
|
|
390
|
+
* const qb = em.createQueryBuilder(Book, 'b');
|
|
391
|
+
* qb.select('*')
|
|
392
|
+
* .joinAndSelect('b.author', 'a')
|
|
393
|
+
* .where({ 'a.name': 'John' });
|
|
394
|
+
* ```
|
|
395
|
+
*/
|
|
396
|
+
joinAndSelect<Field extends QBField<Entity, RootAlias, Context>, Alias extends string, const JoinFields extends readonly string[] | 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>>;
|
|
397
|
+
leftJoinAndSelect<Field extends QBField<Entity, RootAlias, Context>, Alias extends string, const JoinFields extends readonly string[] | 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>>;
|
|
398
|
+
leftJoinLateralAndSelect<Field extends QBField<Entity, RootAlias, Context>, Alias extends string, const JoinFields extends readonly string[] | 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>>;
|
|
399
|
+
innerJoinAndSelect<Field extends QBField<Entity, RootAlias, Context>, Alias extends string, const JoinFields extends readonly string[] | 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>>;
|
|
400
|
+
innerJoinLateralAndSelect<Field extends QBField<Entity, RootAlias, Context>, Alias extends string, const JoinFields extends readonly string[] | 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>>;
|
|
401
|
+
protected getFieldsForJoinedLoad(prop: EntityProperty<Entity>, alias: string, explicitFields?: readonly string[]): InternalField<Entity>[];
|
|
161
402
|
/**
|
|
162
403
|
* Apply filters to the QB where condition.
|
|
163
404
|
*/
|
|
@@ -172,29 +413,191 @@ export declare class QueryBuilder<Entity extends object = AnyEntity, RootAlias e
|
|
|
172
413
|
*/
|
|
173
414
|
applyJoinedFilters(em: EntityManager, filterOptions: FilterOptions | undefined): Promise<void>;
|
|
174
415
|
withSubQuery(subQuery: RawQueryFragment | NativeQueryBuilder, alias: string): this;
|
|
175
|
-
|
|
416
|
+
/**
|
|
417
|
+
* Adds a WHERE clause to the query using an object condition.
|
|
418
|
+
*
|
|
419
|
+
* Supports filtering by:
|
|
420
|
+
* - Direct entity properties: `{ name: 'John' }`
|
|
421
|
+
* - Nested relations/embedded: `{ author: { name: 'John' } }`
|
|
422
|
+
* - Aliased properties after joins: `{ 'a.name': 'John' }` or `{ 'b.title': 'test' }`
|
|
423
|
+
* - Filter operators: `{ age: { $gte: 18 } }`
|
|
424
|
+
* - Logical operators: `{ $or: [{ name: 'John' }, { name: 'Jane' }] }`
|
|
425
|
+
*
|
|
426
|
+
* @example
|
|
427
|
+
* ```ts
|
|
428
|
+
* // Filter by entity properties
|
|
429
|
+
* qb.where({ name: 'John', age: { $gte: 18 } });
|
|
430
|
+
*
|
|
431
|
+
* // Filter by nested relation
|
|
432
|
+
* qb.where({ author: { name: 'John' } });
|
|
433
|
+
*
|
|
434
|
+
* // Filter by aliased properties after join
|
|
435
|
+
* qb.leftJoin('a.books', 'b').where({ 'b.title': 'test' });
|
|
436
|
+
*
|
|
437
|
+
* // Combine with logical operators
|
|
438
|
+
* qb.where({ $or: [{ status: 'active' }, { role: 'admin' }] });
|
|
439
|
+
* ```
|
|
440
|
+
*/
|
|
441
|
+
where(cond: QBFilterQuery<Entity, RootAlias, Context, RawAliases>, operator?: keyof typeof GroupOperator): this;
|
|
442
|
+
/**
|
|
443
|
+
* Adds a WHERE clause to the query using a raw SQL string or fragment.
|
|
444
|
+
*
|
|
445
|
+
* @example
|
|
446
|
+
* ```ts
|
|
447
|
+
* // Raw SQL with parameters
|
|
448
|
+
* qb.where('name = ? AND age >= ?', ['John', 18]);
|
|
449
|
+
*
|
|
450
|
+
* // Using raw() helper
|
|
451
|
+
* qb.where(raw('lower(name) = ?', ['john']));
|
|
452
|
+
* ```
|
|
453
|
+
*/
|
|
176
454
|
where(cond: string | RawQueryFragment, params?: any[], operator?: keyof typeof GroupOperator): this;
|
|
177
|
-
|
|
455
|
+
/**
|
|
456
|
+
* Adds an AND WHERE clause to the query using an object condition.
|
|
457
|
+
*
|
|
458
|
+
* @example
|
|
459
|
+
* ```ts
|
|
460
|
+
* qb.where({ status: 'active' }).andWhere({ role: 'admin' });
|
|
461
|
+
* qb.where({ name: 'John' }).andWhere({ 'b.title': 'test' });
|
|
462
|
+
* ```
|
|
463
|
+
*/
|
|
464
|
+
andWhere(cond: QBFilterQuery<Entity, RootAlias, Context, RawAliases>): this;
|
|
465
|
+
/**
|
|
466
|
+
* Adds an AND WHERE clause to the query using a raw SQL string or fragment.
|
|
467
|
+
*
|
|
468
|
+
* @example
|
|
469
|
+
* ```ts
|
|
470
|
+
* qb.where({ status: 'active' }).andWhere('age >= ?', [18]);
|
|
471
|
+
* ```
|
|
472
|
+
*/
|
|
178
473
|
andWhere(cond: string | RawQueryFragment, params?: any[]): this;
|
|
179
|
-
|
|
474
|
+
/**
|
|
475
|
+
* Adds an OR WHERE clause to the query using an object condition.
|
|
476
|
+
*
|
|
477
|
+
* @example
|
|
478
|
+
* ```ts
|
|
479
|
+
* qb.where({ status: 'active' }).orWhere({ role: 'admin' });
|
|
480
|
+
* qb.where({ name: 'John' }).orWhere({ name: 'Jane' });
|
|
481
|
+
* ```
|
|
482
|
+
*/
|
|
483
|
+
orWhere(cond: QBFilterQuery<Entity, RootAlias, Context, RawAliases>): this;
|
|
484
|
+
/**
|
|
485
|
+
* Adds an OR WHERE clause to the query using a raw SQL string or fragment.
|
|
486
|
+
*
|
|
487
|
+
* @example
|
|
488
|
+
* ```ts
|
|
489
|
+
* qb.where({ status: 'active' }).orWhere('role = ?', ['admin']);
|
|
490
|
+
* ```
|
|
491
|
+
*/
|
|
180
492
|
orWhere(cond: string | RawQueryFragment, params?: any[]): this;
|
|
181
|
-
|
|
182
|
-
|
|
493
|
+
/**
|
|
494
|
+
* Adds an ORDER BY clause to the query, replacing any existing order.
|
|
495
|
+
*
|
|
496
|
+
* @example
|
|
497
|
+
* ```ts
|
|
498
|
+
* qb.orderBy({ name: 'asc', createdAt: 'desc' });
|
|
499
|
+
* qb.orderBy([{ name: 'asc' }, { createdAt: 'desc' }]);
|
|
500
|
+
* qb.orderBy({ profile: { bio: 'asc' } }); // nested via object
|
|
501
|
+
* qb.orderBy({ 'profile.bio': 'asc' }); // nested via dot notation
|
|
502
|
+
* ```
|
|
503
|
+
*/
|
|
504
|
+
orderBy(orderBy: ContextOrderByMap<Entity, RootAlias, Context> | ContextOrderByMap<Entity, RootAlias, Context>[]): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields>;
|
|
505
|
+
/**
|
|
506
|
+
* Adds an ORDER BY clause to the query, replacing any existing order.
|
|
507
|
+
*
|
|
508
|
+
* @example
|
|
509
|
+
* ```ts
|
|
510
|
+
* qb.orderBy({ name: 'asc', createdAt: 'desc' });
|
|
511
|
+
* qb.orderBy([{ name: 'asc' }, { createdAt: 'desc' }]);
|
|
512
|
+
* qb.orderBy({ profile: { bio: 'asc' } }); // nested via object
|
|
513
|
+
* qb.orderBy({ 'profile.bio': 'asc' }); // nested via dot notation
|
|
514
|
+
* ```
|
|
515
|
+
*/
|
|
516
|
+
orderBy<const T extends Record<string, QueryOrderKeysFlat>>(orderBy: T & {
|
|
517
|
+
[K in keyof T]: K extends NestedAutoPath<Entity, RootAlias, Context, K & string> ? T[K] : never;
|
|
518
|
+
}): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields>;
|
|
519
|
+
/**
|
|
520
|
+
* Adds additional ORDER BY clause without replacing existing order.
|
|
521
|
+
*/
|
|
522
|
+
andOrderBy(orderBy: ContextOrderByMap<Entity, RootAlias, Context> | ContextOrderByMap<Entity, RootAlias, Context>[]): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields>;
|
|
523
|
+
/**
|
|
524
|
+
* Adds additional ORDER BY clause without replacing existing order.
|
|
525
|
+
*/
|
|
526
|
+
andOrderBy<const T extends Record<string, QueryOrderKeysFlat>>(orderBy: T & {
|
|
527
|
+
[K in keyof T]: K extends NestedAutoPath<Entity, RootAlias, Context, K & string> ? T[K] : never;
|
|
528
|
+
}): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields>;
|
|
183
529
|
private processOrderBy;
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
530
|
+
/**
|
|
531
|
+
* Adds a GROUP BY clause to the query.
|
|
532
|
+
*
|
|
533
|
+
* @example
|
|
534
|
+
* ```ts
|
|
535
|
+
* qb.select([raw('count(*) as count'), 'status'])
|
|
536
|
+
* .groupBy('status');
|
|
537
|
+
* ```
|
|
538
|
+
*/
|
|
539
|
+
groupBy<const F extends readonly Field<Entity, RootAlias, Context>[]>(fields: F): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields>;
|
|
540
|
+
/**
|
|
541
|
+
* Adds a GROUP BY clause to the query.
|
|
542
|
+
*
|
|
543
|
+
* @example
|
|
544
|
+
* ```ts
|
|
545
|
+
* qb.select([raw('count(*) as count'), 'status'])
|
|
546
|
+
* .groupBy('status');
|
|
547
|
+
* ```
|
|
548
|
+
*/
|
|
549
|
+
groupBy<F extends Field<Entity, RootAlias, Context>>(fields: F): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields>;
|
|
550
|
+
/**
|
|
551
|
+
* Adds a GROUP BY clause to the query.
|
|
552
|
+
*
|
|
553
|
+
* @example
|
|
554
|
+
* ```ts
|
|
555
|
+
* qb.select([raw('count(*) as count'), 'status'])
|
|
556
|
+
* .groupBy('status');
|
|
557
|
+
* ```
|
|
558
|
+
*/
|
|
559
|
+
groupBy<const P extends string>(fields: NestedAutoPath<Entity, RootAlias, Context, P> | readonly NestedAutoPath<Entity, RootAlias, Context, P>[]): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields>;
|
|
560
|
+
/**
|
|
561
|
+
* Adds a HAVING clause to the query, typically used with GROUP BY.
|
|
562
|
+
*
|
|
563
|
+
* @example
|
|
564
|
+
* ```ts
|
|
565
|
+
* qb.select([raw('count(*) as count'), 'status'])
|
|
566
|
+
* .groupBy('status')
|
|
567
|
+
* .having({ count: { $gt: 5 } });
|
|
568
|
+
* ```
|
|
569
|
+
*/
|
|
570
|
+
having(cond?: QBFilterQuery<Entity, RootAlias, Context, RawAliases> | string, params?: any[], operator?: keyof typeof GroupOperator): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields>;
|
|
571
|
+
andHaving(cond?: QBFilterQuery<Entity, RootAlias, Context, RawAliases> | string, params?: any[]): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields>;
|
|
572
|
+
orHaving(cond?: QBFilterQuery<Entity, RootAlias, Context, RawAliases> | string, params?: any[]): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields>;
|
|
573
|
+
onConflict<F extends Field<Entity, RootAlias, Context>>(fields?: F | F[] | RawQueryFragment): InsertQueryBuilder<Entity, RootAlias, Context>;
|
|
189
574
|
ignore(): this;
|
|
190
|
-
merge(data
|
|
191
|
-
|
|
575
|
+
merge<const P extends string>(data: readonly NestedAutoPath<Entity, RootAlias, Context, P>[]): this;
|
|
576
|
+
merge<F extends Field<Entity, RootAlias, Context>>(data?: EntityData<Entity> | F[]): this;
|
|
577
|
+
returning<F extends Field<Entity, RootAlias, Context>>(fields?: F | F[]): this;
|
|
192
578
|
/**
|
|
193
579
|
* @internal
|
|
194
580
|
*/
|
|
195
581
|
populate(populate: PopulateOptions<Entity>[], populateWhere?: ObjectQuery<Entity> | PopulateHint | `${PopulateHint}`, populateFilter?: ObjectQuery<Entity> | PopulateHint | `${PopulateHint}`): this;
|
|
196
|
-
|
|
197
|
-
|
|
582
|
+
/**
|
|
583
|
+
* Sets a LIMIT clause to restrict the number of results.
|
|
584
|
+
*
|
|
585
|
+
* @example
|
|
586
|
+
* ```ts
|
|
587
|
+
* qb.select('*').limit(10); // First 10 results
|
|
588
|
+
* qb.select('*').limit(10, 20); // 10 results starting from offset 20
|
|
589
|
+
* ```
|
|
590
|
+
*/
|
|
591
|
+
limit(limit?: number, offset?: number): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields>;
|
|
592
|
+
/**
|
|
593
|
+
* Sets an OFFSET clause to skip a number of results.
|
|
594
|
+
*
|
|
595
|
+
* @example
|
|
596
|
+
* ```ts
|
|
597
|
+
* qb.select('*').limit(10).offset(20); // Results 21-30
|
|
598
|
+
* ```
|
|
599
|
+
*/
|
|
600
|
+
offset(offset?: number): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields>;
|
|
198
601
|
withSchema(schema?: string): this;
|
|
199
602
|
setLockMode(mode?: LockMode, tables?: string[]): this;
|
|
200
603
|
setFlushMode(flushMode?: FlushMode): this;
|
|
@@ -220,8 +623,12 @@ export declare class QueryBuilder<Entity extends object = AnyEntity, RootAlias e
|
|
|
220
623
|
* Specifies FROM which entity's table select/update/delete will be executed, removing all previously set FROM-s.
|
|
221
624
|
* Allows setting a main string alias of the selection data.
|
|
222
625
|
*/
|
|
223
|
-
from<Entity extends object>(target: QueryBuilder<Entity>, aliasName?: string): SelectQueryBuilder<Entity, RootAlias, Hint, Context>;
|
|
224
|
-
|
|
626
|
+
from<Entity extends object>(target: QueryBuilder<Entity>, aliasName?: string): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields>;
|
|
627
|
+
/**
|
|
628
|
+
* Specifies FROM which entity's table select/update/delete will be executed, removing all previously set FROM-s.
|
|
629
|
+
* Allows setting a main string alias of the selection data.
|
|
630
|
+
*/
|
|
631
|
+
from<Entity extends object>(target: EntityName<Entity>): SelectQueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields>;
|
|
225
632
|
getNativeQuery(processVirtualEntity?: boolean): NativeQueryBuilder;
|
|
226
633
|
/**
|
|
227
634
|
* Returns the query with parameters as wildcards.
|
|
@@ -281,30 +688,30 @@ export declare class QueryBuilder<Entity extends object = AnyEntity, RootAlias e
|
|
|
281
688
|
* }
|
|
282
689
|
* ```
|
|
283
690
|
*/
|
|
284
|
-
stream(options?: QBStreamOptions): AsyncIterableIterator<Loaded<Entity, Hint>>;
|
|
691
|
+
stream(options?: QBStreamOptions): AsyncIterableIterator<Loaded<Entity, Hint, Fields>>;
|
|
285
692
|
/**
|
|
286
693
|
* Alias for `qb.getResultList()`
|
|
287
694
|
*/
|
|
288
|
-
getResult(): Promise<Loaded<Entity, Hint>[]>;
|
|
695
|
+
getResult(): Promise<Loaded<Entity, Hint, Fields>[]>;
|
|
289
696
|
/**
|
|
290
697
|
* Executes the query, returning array of results mapped to entity instances.
|
|
291
698
|
*/
|
|
292
|
-
getResultList(limit?: number): Promise<Loaded<Entity, Hint>[]>;
|
|
699
|
+
getResultList(limit?: number): Promise<Loaded<Entity, Hint, Fields>[]>;
|
|
293
700
|
private propagatePopulateHint;
|
|
294
701
|
private mapResult;
|
|
295
702
|
private mapResults;
|
|
296
703
|
/**
|
|
297
704
|
* Executes the query, returning the first result or null
|
|
298
705
|
*/
|
|
299
|
-
getSingleResult(): Promise<Entity | null>;
|
|
706
|
+
getSingleResult(): Promise<Loaded<Entity, Hint, Fields> | null>;
|
|
300
707
|
/**
|
|
301
708
|
* Executes count query (without offset and limit), returning total count of results
|
|
302
709
|
*/
|
|
303
|
-
getCount(field?:
|
|
710
|
+
getCount<F extends Field<Entity, RootAlias, Context>>(field?: F | F[], distinct?: boolean): Promise<number>;
|
|
304
711
|
/**
|
|
305
712
|
* Executes the query, returning both array of results and total count query (without offset and limit).
|
|
306
713
|
*/
|
|
307
|
-
getResultAndCount(): Promise<[Entity[], number]>;
|
|
714
|
+
getResultAndCount(): Promise<[Loaded<Entity, Hint, Fields>[], number]>;
|
|
308
715
|
/**
|
|
309
716
|
* Returns native query builder instance with sub-query aliased with given alias.
|
|
310
717
|
*/
|
|
@@ -314,7 +721,7 @@ export declare class QueryBuilder<Entity extends object = AnyEntity, RootAlias e
|
|
|
314
721
|
* 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.
|
|
315
722
|
*/
|
|
316
723
|
as<T>(targetEntity: EntityName<T>, alias: EntityKey<T>): NativeQueryBuilder;
|
|
317
|
-
clone(reset?: boolean | string[], preserve?: string[]): QueryBuilder<Entity>;
|
|
724
|
+
clone(reset?: boolean | string[], preserve?: string[]): QueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields>;
|
|
318
725
|
/**
|
|
319
726
|
* Sets logger context for this query builder.
|
|
320
727
|
*/
|
|
@@ -325,7 +732,13 @@ export declare class QueryBuilder<Entity extends object = AnyEntity, RootAlias e
|
|
|
325
732
|
getLoggerContext<T extends Dictionary & LoggingOptions = Dictionary>(): T;
|
|
326
733
|
private fromVirtual;
|
|
327
734
|
private joinReference;
|
|
328
|
-
protected prepareFields<T>(fields:
|
|
735
|
+
protected prepareFields<T>(fields: InternalField<T>[], type?: 'where' | 'groupBy' | 'sub-query', schema?: string): (string | RawQueryFragment)[];
|
|
736
|
+
/**
|
|
737
|
+
* Resolves nested paths like `a.books.title` to their actual field references.
|
|
738
|
+
* Auto-joins relations as needed and returns `{alias}.{field}`.
|
|
739
|
+
* For embeddeds: navigates into flattened embeddeds to return the correct field name.
|
|
740
|
+
*/
|
|
741
|
+
protected resolveNestedPath(field: string): string | string[];
|
|
329
742
|
private init;
|
|
330
743
|
private getQueryBase;
|
|
331
744
|
private applyDiscriminatorCondition;
|
|
@@ -373,11 +786,11 @@ export declare class QueryBuilder<Entity extends object = AnyEntity, RootAlias e
|
|
|
373
786
|
private ensureFromClause;
|
|
374
787
|
private ensureNotFinalized;
|
|
375
788
|
}
|
|
376
|
-
export interface RunQueryBuilder<Entity extends object> extends Omit<QueryBuilder<Entity,
|
|
377
|
-
where(cond: QBFilterQuery<Entity> | string, params?: keyof typeof GroupOperator | any[], operator?: keyof typeof GroupOperator): this;
|
|
789
|
+
export interface RunQueryBuilder<Entity extends object, RootAlias extends string = never, Context extends object = never, RawAliases extends string = never> extends Omit<QueryBuilder<Entity, RootAlias, never, Context, RawAliases, '*'>, 'getResult' | 'getSingleResult' | 'getResultList' | 'where'> {
|
|
790
|
+
where(cond: QBFilterQuery<Entity, RootAlias, Context, RawAliases> | string, params?: keyof typeof GroupOperator | any[], operator?: keyof typeof GroupOperator): this;
|
|
378
791
|
execute<Result = QueryResult<Entity>>(method?: 'all' | 'get' | 'run', mapResults?: boolean): Promise<Result>;
|
|
379
792
|
}
|
|
380
|
-
export interface SelectQueryBuilder<Entity extends object = AnyEntity, RootAlias extends string = never, Hint extends string = never, Context extends object = never> extends QueryBuilder<Entity, RootAlias, Hint, Context> {
|
|
793
|
+
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 = '*'> extends QueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields> {
|
|
381
794
|
execute<Result = Entity[]>(method?: 'all' | 'get' | 'run', mapResults?: boolean): Promise<Result>;
|
|
382
795
|
execute<Result = Entity[]>(method: 'all', mapResults?: boolean): Promise<Result>;
|
|
383
796
|
execute<Result = Entity>(method: 'get', mapResults?: boolean): Promise<Result>;
|
|
@@ -397,11 +810,11 @@ export interface CountQueryBuilder<Entity extends object> extends QueryBuilder<E
|
|
|
397
810
|
count: number;
|
|
398
811
|
}>>(method: 'run', mapResults?: boolean): Promise<Result>;
|
|
399
812
|
}
|
|
400
|
-
export interface InsertQueryBuilder<T extends object> extends RunQueryBuilder<T> {
|
|
813
|
+
export interface InsertQueryBuilder<T extends object, RootAlias extends string = never, Context extends object = never> extends RunQueryBuilder<T, RootAlias, Context> {
|
|
401
814
|
}
|
|
402
|
-
export interface UpdateQueryBuilder<T extends object> extends RunQueryBuilder<T> {
|
|
815
|
+
export interface UpdateQueryBuilder<T extends object, RootAlias extends string = never, Context extends object = never> extends RunQueryBuilder<T, RootAlias, Context> {
|
|
403
816
|
}
|
|
404
|
-
export interface DeleteQueryBuilder<T extends object> extends RunQueryBuilder<T> {
|
|
817
|
+
export interface DeleteQueryBuilder<T extends object, RootAlias extends string = never, Context extends object = never> extends RunQueryBuilder<T, RootAlias, Context> {
|
|
405
818
|
}
|
|
406
819
|
export interface TruncateQueryBuilder<T extends object> extends RunQueryBuilder<T> {
|
|
407
820
|
}
|