@mikro-orm/knex 6.2.10-dev.2 → 6.2.10-dev.3

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.
@@ -20,7 +20,7 @@ export declare abstract class AbstractSqlDriver<Connection extends AbstractSqlCo
20
20
  countVirtual<T extends object>(entityName: string, where: FilterQuery<T>, options: CountOptions<T, any>): Promise<number>;
21
21
  protected findFromVirtual<T extends object>(entityName: string, where: FilterQuery<T>, options: FindOptions<T, any> | CountOptions<T, any>, type: QueryType): Promise<EntityData<T>[] | number>;
22
22
  protected wrapVirtualExpressionInSubquery<T extends object>(meta: EntityMetadata<T>, expression: string, where: FilterQuery<T>, options: FindOptions<T, any>, type: QueryType): Promise<T[] | number>;
23
- mapResult<T extends object>(result: EntityData<T>, meta: EntityMetadata<T>, populate?: PopulateOptions<T>[], qb?: QueryBuilder<T>, map?: Dictionary): EntityData<T> | null;
23
+ mapResult<T extends object>(result: EntityData<T>, meta: EntityMetadata<T>, populate?: PopulateOptions<T>[], qb?: QueryBuilder<T, any, any, any>, map?: Dictionary): EntityData<T> | null;
24
24
  private mapJoinedProps;
25
25
  count<T extends object>(entityName: string, where: any, options?: CountOptions<T>): Promise<number>;
26
26
  nativeInsert<T extends object>(entityName: string, data: EntityDictionary<T>, options?: NativeInsertUpdateOptions<T>): Promise<QueryResult<T>>;
@@ -52,16 +52,16 @@ export declare abstract class AbstractSqlDriver<Connection extends AbstractSqlCo
52
52
  * @internal
53
53
  */
54
54
  mergeJoinedResult<T extends object>(rawResults: EntityData<T>[], meta: EntityMetadata<T>, joinedProps: PopulateOptions<T>[]): EntityData<T>[];
55
- protected getFieldsForJoinedLoad<T extends object>(qb: QueryBuilder<T>, meta: EntityMetadata<T>, explicitFields?: Field<T>[], exclude?: Field<T>[], populate?: PopulateOptions<T>[], options?: {
55
+ protected getFieldsForJoinedLoad<T extends object>(qb: QueryBuilder<T, any, any, any>, meta: EntityMetadata<T>, explicitFields?: Field<T>[], exclude?: Field<T>[], populate?: PopulateOptions<T>[], options?: {
56
56
  strategy?: Options['loadStrategy'];
57
57
  populateWhere?: FindOptions<any>['populateWhere'];
58
58
  }, parentTableAlias?: string, parentJoinPath?: string): Field<T>[];
59
59
  /**
60
60
  * @internal
61
61
  */
62
- mapPropToFieldNames<T extends object>(qb: QueryBuilder<T>, prop: EntityProperty<T>, tableAlias?: string): Field<T>[];
62
+ mapPropToFieldNames<T extends object>(qb: QueryBuilder<T, any, any, any>, prop: EntityProperty<T>, tableAlias?: string): Field<T>[];
63
63
  /** @internal */
64
- createQueryBuilder<T extends object>(entityName: EntityName<T> | QueryBuilder<T>, ctx?: Transaction<Knex.Transaction>, preferredConnectionType?: ConnectionType, convertCustomTypes?: boolean, loggerContext?: LoggingOptions, alias?: string, em?: SqlEntityManager): QueryBuilder<T>;
64
+ createQueryBuilder<T extends object>(entityName: EntityName<T> | QueryBuilder<T, any, any, any>, ctx?: Transaction<Knex.Transaction>, preferredConnectionType?: ConnectionType, convertCustomTypes?: boolean, loggerContext?: LoggingOptions, alias?: string, em?: SqlEntityManager): QueryBuilder<T, any, any, any>;
65
65
  protected resolveConnectionType(args: {
66
66
  ctx?: Transaction<Knex.Transaction>;
67
67
  connectionType?: ConnectionType;
@@ -70,10 +70,10 @@ export declare abstract class AbstractSqlDriver<Connection extends AbstractSqlCo
70
70
  protected processManyToMany<T extends object>(meta: EntityMetadata<T> | undefined, pks: Primary<T>[], collections: EntityData<T>, clear: boolean, options?: DriverMethodOptions): Promise<void>;
71
71
  lockPessimistic<T extends object>(entity: T, options: LockOptions): Promise<void>;
72
72
  protected buildPopulateWhere<T extends object>(meta: EntityMetadata<T>, joinedProps: PopulateOptions<T>[], options: Pick<FindOptions<any>, 'populateWhere'>): ObjectQuery<T>;
73
- protected buildOrderBy<T extends object>(qb: QueryBuilder<T>, meta: EntityMetadata<T>, populate: PopulateOptions<T>[], options: Pick<FindOptions<any>, 'strategy' | 'orderBy' | 'populateOrderBy'>): QueryOrderMap<T>[];
74
- protected buildPopulateOrderBy<T extends object>(qb: QueryBuilder<T>, meta: EntityMetadata<T>, populateOrderBy: QueryOrderMap<T>[], parentPath: string, explicit: boolean, parentAlias?: string): QueryOrderMap<T>[];
75
- protected buildJoinedPropsOrderBy<T extends object>(qb: QueryBuilder<T>, meta: EntityMetadata<T>, populate: PopulateOptions<T>[], options?: Pick<FindOptions<any>, 'strategy' | 'orderBy' | 'populateOrderBy'>, parentPath?: string): QueryOrderMap<T>[];
73
+ protected buildOrderBy<T extends object>(qb: QueryBuilder<T, any, any, any>, meta: EntityMetadata<T>, populate: PopulateOptions<T>[], options: Pick<FindOptions<any>, 'strategy' | 'orderBy' | 'populateOrderBy'>): QueryOrderMap<T>[];
74
+ protected buildPopulateOrderBy<T extends object>(qb: QueryBuilder<T, any, any, any>, meta: EntityMetadata<T>, populateOrderBy: QueryOrderMap<T>[], parentPath: string, explicit: boolean, parentAlias?: string): QueryOrderMap<T>[];
75
+ protected buildJoinedPropsOrderBy<T extends object>(qb: QueryBuilder<T, any, any, any>, meta: EntityMetadata<T>, populate: PopulateOptions<T>[], options?: Pick<FindOptions<any>, 'strategy' | 'orderBy' | 'populateOrderBy'>, parentPath?: string): QueryOrderMap<T>[];
76
76
  protected normalizeFields<T extends object>(fields: Field<T>[], prefix?: string): string[];
77
- protected processField<T extends object>(meta: EntityMetadata<T>, prop: EntityProperty<T> | undefined, field: string, ret: Field<T>[], populate: PopulateOptions<T>[], joinedProps: PopulateOptions<T>[], qb: QueryBuilder<T>): void;
78
- protected buildFields<T extends object>(meta: EntityMetadata<T>, populate: PopulateOptions<T>[], joinedProps: PopulateOptions<T>[], qb: QueryBuilder<T>, alias: string, options: Pick<FindOptions<T, any, any, any>, 'strategy' | 'fields' | 'exclude'>): Field<T>[];
77
+ protected processField<T extends object>(meta: EntityMetadata<T>, prop: EntityProperty<T> | undefined, field: string, ret: Field<T>[], populate: PopulateOptions<T>[], joinedProps: PopulateOptions<T>[], qb: QueryBuilder<T, any, any, any>): void;
78
+ protected buildFields<T extends object>(meta: EntityMetadata<T>, populate: PopulateOptions<T>[], joinedProps: PopulateOptions<T>[], qb: QueryBuilder<T, any, any, any>, alias: string, options: Pick<FindOptions<T, any, any, any>, 'strategy' | 'fields' | 'exclude'>): Field<T>[];
79
79
  }
@@ -10,11 +10,11 @@ export declare class SqlEntityManager<Driver extends AbstractSqlDriver = Abstrac
10
10
  /**
11
11
  * Creates a QueryBuilder instance
12
12
  */
13
- createQueryBuilder<T extends object>(entityName: EntityName<T> | QueryBuilder<T>, alias?: string, type?: ConnectionType, loggerContext?: LoggingOptions): QueryBuilder<T>;
13
+ createQueryBuilder<Entity extends object, RootAlias extends string = never>(entityName: EntityName<Entity> | QueryBuilder<Entity>, alias?: RootAlias, type?: ConnectionType, loggerContext?: LoggingOptions): QueryBuilder<Entity, RootAlias>;
14
14
  /**
15
15
  * Shortcut for `createQueryBuilder()`
16
16
  */
17
- qb<T extends object>(entityName: EntityName<T>, alias?: string, type?: ConnectionType, loggerContext?: LoggingOptions): QueryBuilder<T>;
17
+ qb<Entity extends object, RootAlias extends string = never>(entityName: EntityName<Entity>, alias?: RootAlias, type?: ConnectionType, loggerContext?: LoggingOptions): QueryBuilder<Entity, RootAlias, never, never>;
18
18
  /**
19
19
  * Returns configured knex instance.
20
20
  */
@@ -2,17 +2,17 @@ import type { Knex } from 'knex';
2
2
  import { EntityRepository, type ConnectionType, type EntityName } from '@mikro-orm/core';
3
3
  import type { SqlEntityManager } from './SqlEntityManager';
4
4
  import type { QueryBuilder } from './query';
5
- export declare class SqlEntityRepository<T extends object> extends EntityRepository<T> {
5
+ export declare class SqlEntityRepository<Entity extends object> extends EntityRepository<Entity> {
6
6
  protected readonly em: SqlEntityManager;
7
- constructor(em: SqlEntityManager, entityName: EntityName<T>);
7
+ constructor(em: SqlEntityManager, entityName: EntityName<Entity>);
8
8
  /**
9
9
  * Creates a QueryBuilder instance
10
10
  */
11
- createQueryBuilder(alias?: string): QueryBuilder<T>;
11
+ createQueryBuilder<RootAlias extends string = never>(alias?: RootAlias): QueryBuilder<Entity, RootAlias>;
12
12
  /**
13
13
  * Shortcut for `createQueryBuilder()`
14
14
  */
15
- qb(alias?: string): QueryBuilder<T>;
15
+ qb<RootAlias extends string = never>(alias?: RootAlias): QueryBuilder<Entity, RootAlias>;
16
16
  /**
17
17
  * Returns configured knex instance.
18
18
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/knex",
3
- "version": "6.2.10-dev.2",
3
+ "version": "6.2.10-dev.3",
4
4
  "description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",
@@ -66,7 +66,7 @@
66
66
  "@mikro-orm/core": "^6.2.9"
67
67
  },
68
68
  "peerDependencies": {
69
- "@mikro-orm/core": "6.2.10-dev.2",
69
+ "@mikro-orm/core": "6.2.10-dev.3",
70
70
  "better-sqlite3": "*",
71
71
  "libsql": "*",
72
72
  "mariadb": "*"
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import { inspect } from 'util';
3
3
  import type { Knex } from 'knex';
4
- import { type AnyEntity, type ConnectionType, type Dictionary, type EntityData, type EntityMetadata, type EntityName, type EntityProperty, type FlushMode, type GroupOperator, LockMode, type LoggingOptions, type MetadataStorage, type ObjectQuery, PopulateHint, type PopulateOptions, type QBFilterQuery, type QBQueryOrderMap, QueryFlag, type QueryOrderMap, type QueryResult, type RequiredEntityData } from '@mikro-orm/core';
4
+ import { type AnyEntity, type ConnectionType, type Dictionary, type EntityData, type EntityKey, type EntityMetadata, type EntityName, type EntityProperty, type FlushMode, type GroupOperator, type Loaded, LockMode, type LoggingOptions, type MetadataStorage, type ObjectQuery, PopulateHint, type PopulateOptions, type QBFilterQuery, type QBQueryOrderMap, QueryFlag, type QueryOrderMap, type QueryResult, type RequiredEntityData, type ExpandProperty } from '@mikro-orm/core';
5
5
  import { JoinType, QueryType } from './enums';
6
6
  import type { AbstractSqlDriver } from '../AbstractSqlDriver';
7
7
  import { type Alias, QueryBuilderHelper } from './QueryBuilderHelper';
@@ -12,6 +12,26 @@ export interface ExecuteOptions {
12
12
  mapResults?: boolean;
13
13
  mergeResults?: boolean;
14
14
  }
15
+ type AnyString = string & {};
16
+ type Compute<T> = {
17
+ [K in keyof T]: T[K];
18
+ } & {};
19
+ type IsNever<T, True = true, False = false> = [T] extends [never] ? True : False;
20
+ type GetAlias<T extends string> = T extends `${infer A}.${string}` ? A : never;
21
+ type GetPropName<T extends string> = T extends `${string}.${infer P}` ? P : T;
22
+ type AppendToHint<Parent extends string, Child extends string> = `${Parent}.${Child}`;
23
+ type AddToContext<Type extends object, Context, Field extends string, Alias extends string, Select extends boolean> = {
24
+ [K in Alias]: [GetPath<Context, Field>, K, ExpandProperty<Type[GetPropName<Field> & keyof Type]>, Select];
25
+ };
26
+ 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>;
27
+ 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;
28
+ 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;
29
+ export type ModifyHint<RootAlias, Context, Hint extends string, Field extends string, Select extends boolean = false> = Hint | AddToHint<RootAlias, Context, Field, Select>;
30
+ export type ModifyContext<Entity extends object, Context, Field extends string, Alias extends string, Select extends boolean = false> = Compute<IsNever<Context> extends true ? AddToContext<GetType<Entity, object, Field>, object, Field, Alias, Select> : Context & AddToContext<GetType<Entity, Context, Field>, Context, Field, Alias, Select>>;
31
+ type EntityRelations<T> = EntityKey<T, true>;
32
+ type AddAliasesFromContext<Context> = Context[keyof Context] extends infer Join ? Join extends any ? Join extends [string, infer Alias, infer Type, any] ? `${Alias & string}.${EntityRelations<Type & {}>}` : never : never : never;
33
+ export type QBField<Entity, RootAlias extends string, Context> = (EntityRelations<Entity> | `${RootAlias}.${EntityRelations<Entity>}` | AddAliasesFromContext<Context>) & {} | AnyString;
34
+ export type QBField2<Entity, RootAlias extends string, Context> = (EntityKey<Entity> | `${RootAlias}.${EntityKey<Entity>}` | AddAliasesFromContext<Context>) & {} | AnyString;
15
35
  /**
16
36
  * SQL query builder with fluent interface.
17
37
  *
@@ -31,26 +51,26 @@ export interface ExecuteOptions {
31
51
  * const publisher = await qb.getSingleResult();
32
52
  * ```
33
53
  */
34
- export declare class QueryBuilder<T extends object = AnyEntity> {
54
+ export declare class QueryBuilder<Entity extends object = AnyEntity, RootAlias extends string = never, Hint extends string = never, Context extends object = never> {
35
55
  protected readonly metadata: MetadataStorage;
36
56
  protected readonly driver: AbstractSqlDriver;
37
57
  protected readonly context?: Knex.Transaction<any, any[]> | undefined;
38
58
  protected connectionType?: ConnectionType | undefined;
39
59
  protected em?: SqlEntityManager<AbstractSqlDriver<import("..").AbstractSqlConnection, AbstractSqlPlatform>> | undefined;
40
60
  protected loggerContext?: (LoggingOptions & Dictionary) | undefined;
41
- get mainAlias(): Alias<T>;
61
+ get mainAlias(): Alias<Entity>;
42
62
  get alias(): string;
43
63
  get helper(): QueryBuilderHelper;
44
64
  /** @internal */
45
65
  type?: QueryType;
46
66
  /** @internal */
47
- _fields?: Field<T>[];
67
+ _fields?: Field<Entity>[];
48
68
  /** @internal */
49
- _populate: PopulateOptions<T>[];
69
+ _populate: PopulateOptions<Entity>[];
50
70
  /** @internal */
51
- _populateWhere?: ObjectQuery<T> | PopulateHint | `${PopulateHint}`;
71
+ _populateWhere?: ObjectQuery<Entity> | PopulateHint | `${PopulateHint}`;
52
72
  /** @internal */
53
- __populateWhere?: ObjectQuery<T> | PopulateHint | `${PopulateHint}`;
73
+ __populateWhere?: ObjectQuery<Entity> | PopulateHint | `${PopulateHint}`;
54
74
  /** @internal */
55
75
  _populateMap: Dictionary<string>;
56
76
  /** @internal */
@@ -63,15 +83,15 @@ export declare class QueryBuilder<T extends object = AnyEntity> {
63
83
  protected _schema?: string;
64
84
  protected _cond: Dictionary;
65
85
  protected _data: Dictionary;
66
- protected _orderBy: QueryOrderMap<T>[];
67
- protected _groupBy: Field<T>[];
86
+ protected _orderBy: QueryOrderMap<Entity>[];
87
+ protected _groupBy: Field<Entity>[];
68
88
  protected _having: Dictionary;
69
- protected _returning?: Field<T>[];
89
+ protected _returning?: Field<Entity>[];
70
90
  protected _onConflict?: {
71
91
  fields: string[];
72
92
  ignore?: boolean;
73
- merge?: EntityData<T> | Field<T>[];
74
- where?: QBFilterQuery<T>;
93
+ merge?: EntityData<Entity> | Field<Entity>[];
94
+ where?: QBFilterQuery<Entity>;
75
95
  }[];
76
96
  protected _limit?: number;
77
97
  protected _offset?: number;
@@ -85,62 +105,62 @@ export declare class QueryBuilder<T extends object = AnyEntity> {
85
105
  protected lockMode?: LockMode;
86
106
  protected lockTables?: string[];
87
107
  protected subQueries: Dictionary<string>;
88
- protected _mainAlias?: Alias<T>;
108
+ protected _mainAlias?: Alias<Entity>;
89
109
  protected _aliases: Dictionary<Alias<any>>;
90
110
  protected _helper?: QueryBuilderHelper;
91
111
  protected _query?: {
92
112
  sql?: string;
93
113
  _sql?: Knex.Sql;
94
114
  params?: readonly unknown[];
95
- qb: Knex.QueryBuilder<T>;
115
+ qb: Knex.QueryBuilder<Entity>;
96
116
  };
97
117
  protected readonly platform: AbstractSqlPlatform;
98
118
  protected readonly knex: Knex;
99
119
  /**
100
120
  * @internal
101
121
  */
102
- constructor(entityName: EntityName<T> | QueryBuilder<T>, metadata: MetadataStorage, driver: AbstractSqlDriver, context?: Knex.Transaction<any, any[]> | undefined, alias?: string, connectionType?: ConnectionType | undefined, em?: SqlEntityManager<AbstractSqlDriver<import("..").AbstractSqlConnection, AbstractSqlPlatform>> | undefined, loggerContext?: (LoggingOptions & Dictionary) | undefined);
103
- select(fields: Field<T> | Field<T>[], distinct?: boolean): SelectQueryBuilder<T>;
104
- addSelect(fields: Field<T> | Field<T>[]): SelectQueryBuilder<T>;
105
- distinct(): SelectQueryBuilder<T>;
122
+ constructor(entityName: EntityName<Entity> | QueryBuilder<Entity, any, any>, metadata: MetadataStorage, driver: AbstractSqlDriver, context?: Knex.Transaction<any, any[]> | undefined, alias?: string, connectionType?: ConnectionType | undefined, em?: SqlEntityManager<AbstractSqlDriver<import("..").AbstractSqlConnection, AbstractSqlPlatform>> | undefined, loggerContext?: (LoggingOptions & Dictionary) | undefined);
123
+ select(fields: Field<Entity> | Field<Entity>[], distinct?: boolean): SelectQueryBuilder<Entity, RootAlias, Hint, Context>;
124
+ addSelect(fields: Field<Entity> | Field<Entity>[]): SelectQueryBuilder<Entity, RootAlias, Hint, Context>;
125
+ distinct(): SelectQueryBuilder<Entity, RootAlias, Hint, Context>;
106
126
  /** postgres only */
107
- distinctOn(fields: string | string[]): SelectQueryBuilder<T>;
108
- insert(data: RequiredEntityData<T> | RequiredEntityData<T>[]): InsertQueryBuilder<T>;
109
- update(data: EntityData<T>): UpdateQueryBuilder<T>;
110
- delete(cond?: QBFilterQuery): DeleteQueryBuilder<T>;
111
- truncate(): TruncateQueryBuilder<T>;
112
- count(field?: string | string[], distinct?: boolean): CountQueryBuilder<T>;
113
- join(field: string | Knex.QueryBuilder | QueryBuilder<any>, alias: string, cond?: QBFilterQuery, type?: JoinType, path?: string, schema?: string): this;
114
- innerJoin(field: string | Knex.QueryBuilder | QueryBuilder<any>, alias: string, cond?: QBFilterQuery, schema?: string): this;
115
- innerJoinLateral(field: string | Knex.QueryBuilder | QueryBuilder<any>, alias: string, cond?: QBFilterQuery, schema?: string): this;
116
- leftJoin(field: string | Knex.QueryBuilder | QueryBuilder<any>, alias: string, cond?: QBFilterQuery, schema?: string): this;
117
- leftJoinLateral(field: string | Knex.QueryBuilder | QueryBuilder<any>, alias: string, cond?: QBFilterQuery, schema?: string): this;
118
- joinAndSelect(field: string | [field: string, qb: Knex.QueryBuilder | QueryBuilder<any>], alias: string, cond?: QBFilterQuery, type?: JoinType, path?: string, fields?: string[], schema?: string): SelectQueryBuilder<T>;
119
- leftJoinAndSelect(field: string | [field: string, qb: Knex.QueryBuilder | QueryBuilder<any>], alias: string, cond?: QBFilterQuery, fields?: string[], schema?: string): SelectQueryBuilder<T>;
120
- leftJoinLateralAndSelect(field: string | [field: string, qb: Knex.QueryBuilder | QueryBuilder<any>], alias: string, cond?: QBFilterQuery, fields?: string[], schema?: string): SelectQueryBuilder<T>;
121
- innerJoinAndSelect(field: string | [field: string, qb: Knex.QueryBuilder | QueryBuilder<any>], alias: string, cond?: QBFilterQuery, fields?: string[], schema?: string): SelectQueryBuilder<T>;
122
- innerJoinLateralAndSelect(field: string | [field: string, qb: Knex.QueryBuilder | QueryBuilder<any>], alias: string, cond?: QBFilterQuery, fields?: string[], schema?: string): SelectQueryBuilder<T>;
123
- protected getFieldsForJoinedLoad(prop: EntityProperty<T>, alias: string, explicitFields?: string[]): Field<T>[];
127
+ distinctOn(fields: string | string[]): SelectQueryBuilder<Entity, RootAlias, Hint, Context>;
128
+ insert(data: RequiredEntityData<Entity> | RequiredEntityData<Entity>[]): InsertQueryBuilder<Entity>;
129
+ update(data: EntityData<Entity>): UpdateQueryBuilder<Entity>;
130
+ delete(cond?: QBFilterQuery): DeleteQueryBuilder<Entity>;
131
+ truncate(): TruncateQueryBuilder<Entity>;
132
+ count(field?: string | string[], distinct?: boolean): CountQueryBuilder<Entity>;
133
+ join<Field extends QBField<Entity, RootAlias, Context>, Alias extends string>(field: Field | Knex.QueryBuilder | QueryBuilder<any>, alias: Alias, cond?: QBFilterQuery, type?: JoinType, path?: string, schema?: string): SelectQueryBuilder<Entity, RootAlias, ModifyHint<RootAlias, Context, Hint, Field> & {}, ModifyContext<Entity, Context, Field, Alias>>;
134
+ innerJoin<Field extends QBField<Entity, RootAlias, Context>, Alias extends string>(field: Field | Knex.QueryBuilder | QueryBuilder<any>, alias: Alias, cond?: QBFilterQuery, schema?: string): SelectQueryBuilder<Entity, RootAlias, ModifyHint<RootAlias, Context, Hint, Field> & {}, ModifyContext<Entity, Context, Field, Alias>>;
135
+ innerJoinLateral(field: Knex.QueryBuilder | QueryBuilder<any>, alias: string, cond?: QBFilterQuery, schema?: string): this;
136
+ leftJoin<Field extends QBField<Entity, RootAlias, Context>, Alias extends string>(field: Field | Knex.QueryBuilder | QueryBuilder<any>, alias: Alias, cond?: QBFilterQuery, schema?: string): SelectQueryBuilder<Entity, RootAlias, ModifyHint<RootAlias, Context, Hint, Field> & {}, ModifyContext<Entity, Context, Field, Alias>>;
137
+ leftJoinLateral(field: Knex.QueryBuilder | QueryBuilder<any>, alias: string, cond?: QBFilterQuery, schema?: string): this;
138
+ joinAndSelect<Field extends QBField<Entity, RootAlias, Context>, Alias extends string>(field: Field | [field: Field, qb: Knex.QueryBuilder | QueryBuilder<any>], alias: Alias, cond?: QBFilterQuery, type?: JoinType, path?: string, fields?: string[], schema?: string): SelectQueryBuilder<Entity, RootAlias, ModifyHint<RootAlias, Context, Hint, Field, true> & {}, ModifyContext<Entity, Context, Field, Alias, true>>;
139
+ leftJoinAndSelect<Field extends QBField<Entity, RootAlias, Context>, Alias extends string>(field: Field | [field: Field, qb: Knex.QueryBuilder | QueryBuilder<any>], alias: Alias, cond?: QBFilterQuery, fields?: string[], schema?: string): SelectQueryBuilder<Entity, RootAlias, ModifyHint<RootAlias, Context, Hint, Field, true> & {}, ModifyContext<Entity, Context, Field, Alias, true>>;
140
+ leftJoinLateralAndSelect<Field extends QBField<Entity, RootAlias, Context>, Alias extends string>(field: [field: Field, qb: Knex.QueryBuilder | QueryBuilder<any>], alias: Alias, cond?: QBFilterQuery, fields?: string[], schema?: string): SelectQueryBuilder<Entity, RootAlias, ModifyHint<RootAlias, Context, Hint, Field, true> & {}, ModifyContext<Entity, Context, Field, Alias, true>>;
141
+ innerJoinAndSelect<Field extends QBField<Entity, RootAlias, Context>, Alias extends string>(field: Field | [field: Field, qb: Knex.QueryBuilder | QueryBuilder<any>], alias: Alias, cond?: QBFilterQuery, fields?: string[], schema?: string): SelectQueryBuilder<Entity, RootAlias, ModifyHint<RootAlias, Context, Hint, Field, true> & {}, ModifyContext<Entity, Context, Field, Alias, true>>;
142
+ innerJoinLateralAndSelect<Field extends QBField<Entity, RootAlias, Context>, Alias extends string>(field: [field: Field, qb: Knex.QueryBuilder | QueryBuilder<any>], alias: Alias, cond?: QBFilterQuery, fields?: string[], schema?: string): SelectQueryBuilder<Entity, RootAlias, ModifyHint<RootAlias, Context, Hint, Field, true> & {}, ModifyContext<Entity, Context, Field, Alias, true>>;
143
+ protected getFieldsForJoinedLoad(prop: EntityProperty<Entity>, alias: string, explicitFields?: string[]): Field<Entity>[];
124
144
  withSubQuery(subQuery: Knex.QueryBuilder, alias: string): this;
125
- where(cond: QBFilterQuery<T>, operator?: keyof typeof GroupOperator): this;
145
+ where(cond: QBFilterQuery<Entity>, operator?: keyof typeof GroupOperator): this;
126
146
  where(cond: string, params?: any[], operator?: keyof typeof GroupOperator): this;
127
- andWhere(cond: QBFilterQuery<T>): this;
147
+ andWhere(cond: QBFilterQuery<Entity>): this;
128
148
  andWhere(cond: string, params?: any[]): this;
129
- orWhere(cond: QBFilterQuery<T>): this;
149
+ orWhere(cond: QBFilterQuery<Entity>): this;
130
150
  orWhere(cond: string, params?: any[]): this;
131
- orderBy(orderBy: QBQueryOrderMap<T> | QBQueryOrderMap<T>[]): SelectQueryBuilder<T>;
132
- groupBy(fields: (string | keyof T) | readonly (string | keyof T)[]): SelectQueryBuilder<T>;
133
- having(cond?: QBFilterQuery | string, params?: any[]): SelectQueryBuilder<T>;
134
- onConflict(fields?: Field<T> | Field<T>[]): InsertQueryBuilder<T>;
151
+ orderBy(orderBy: QBQueryOrderMap<Entity> | QBQueryOrderMap<Entity>[]): SelectQueryBuilder<Entity, RootAlias, Hint, Context>;
152
+ groupBy(fields: (string | keyof Entity) | readonly (string | keyof Entity)[]): SelectQueryBuilder<Entity, RootAlias, Hint, Context>;
153
+ having(cond?: QBFilterQuery | string, params?: any[]): SelectQueryBuilder<Entity, RootAlias, Hint, Context>;
154
+ onConflict(fields?: Field<Entity> | Field<Entity>[]): InsertQueryBuilder<Entity>;
135
155
  ignore(): this;
136
- merge(data?: EntityData<T> | Field<T>[]): this;
137
- returning(fields?: Field<T> | Field<T>[]): this;
156
+ merge(data?: EntityData<Entity> | Field<Entity>[]): this;
157
+ returning(fields?: Field<Entity> | Field<Entity>[]): this;
138
158
  /**
139
159
  * @internal
140
160
  */
141
- populate(populate: PopulateOptions<T>[], populateWhere?: ObjectQuery<T> | PopulateHint | `${PopulateHint}`): this;
142
- limit(limit?: number, offset?: number): SelectQueryBuilder<T>;
143
- offset(offset?: number): SelectQueryBuilder<T>;
161
+ populate(populate: PopulateOptions<Entity>[], populateWhere?: ObjectQuery<Entity> | PopulateHint | `${PopulateHint}`): this;
162
+ limit(limit?: number, offset?: number): SelectQueryBuilder<Entity, RootAlias, Hint, Context>;
163
+ offset(offset?: number): SelectQueryBuilder<Entity, RootAlias, Hint, Context>;
144
164
  withSchema(schema?: string): this;
145
165
  setLockMode(mode?: LockMode, tables?: string[]): this;
146
166
  setFlushMode(flushMode?: FlushMode): this;
@@ -166,8 +186,8 @@ export declare class QueryBuilder<T extends object = AnyEntity> {
166
186
  * Specifies FROM which entity's table select/update/delete will be executed, removing all previously set FROM-s.
167
187
  * Allows setting a main string alias of the selection data.
168
188
  */
169
- from<T extends AnyEntity<T> = AnyEntity>(target: QueryBuilder<T>, aliasName?: string): SelectQueryBuilder<T>;
170
- from<T extends AnyEntity<T> = AnyEntity>(target: EntityName<T>): SelectQueryBuilder<T>;
189
+ from<Entity extends AnyEntity<Entity> = AnyEntity>(target: QueryBuilder<Entity>, aliasName?: string): SelectQueryBuilder<Entity, RootAlias, Hint, Context>;
190
+ from<Entity extends AnyEntity<Entity> = AnyEntity>(target: EntityName<Entity>): SelectQueryBuilder<Entity, RootAlias, Hint, Context>;
171
191
  getKnexQuery(processVirtualEntity?: boolean): Knex.QueryBuilder;
172
192
  /**
173
193
  * @internal
@@ -214,15 +234,15 @@ export declare class QueryBuilder<T extends object = AnyEntity> {
214
234
  /**
215
235
  * Alias for `qb.getResultList()`
216
236
  */
217
- getResult(): Promise<T[]>;
237
+ getResult(): Promise<Loaded<Entity, Hint>[]>;
218
238
  /**
219
239
  * Executes the query, returning array of results
220
240
  */
221
- getResultList(limit?: number): Promise<T[]>;
241
+ getResultList(limit?: number): Promise<Loaded<Entity, Hint>[]>;
222
242
  /**
223
243
  * Executes the query, returning the first result or null
224
244
  */
225
- getSingleResult(): Promise<T | null>;
245
+ getSingleResult(): Promise<Entity | null>;
226
246
  /**
227
247
  * Executes count query (without offset and limit), returning total count of results
228
248
  */
@@ -230,17 +250,17 @@ export declare class QueryBuilder<T extends object = AnyEntity> {
230
250
  /**
231
251
  * Executes the query, returning both array of results and total count query (without offset and limit).
232
252
  */
233
- getResultAndCount(): Promise<[T[], number]>;
253
+ getResultAndCount(): Promise<[Entity[], number]>;
234
254
  /**
235
255
  * Provides promise-like interface so we can await the QB instance.
236
256
  */
237
- then<TResult1 = any, TResult2 = never>(onfulfilled?: ((value: any) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<T[] | number | QueryResult<T>>;
257
+ then<TResult1 = any, TResult2 = never>(onfulfilled?: ((value: any) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<Loaded<Entity, Hint>[] | number | QueryResult<Entity>>;
238
258
  /**
239
259
  * Returns knex instance with sub-query aliased with given alias.
240
260
  * You can provide `EntityName.propName` as alias, then the field name will be used based on the metadata
241
261
  */
242
262
  as(alias: string): Knex.QueryBuilder;
243
- clone(reset?: boolean | string[]): QueryBuilder<T>;
263
+ clone(reset?: boolean | string[]): QueryBuilder<Entity>;
244
264
  getKnex(processVirtualEntity?: boolean): Knex.QueryBuilder;
245
265
  /**
246
266
  * Sets logger context for this query builder.
@@ -272,31 +292,31 @@ export declare class QueryBuilder<T extends object = AnyEntity> {
272
292
  /** @ignore */
273
293
  [inspect.custom](depth?: number): string;
274
294
  }
275
- export interface RunQueryBuilder<T extends object> extends Omit<QueryBuilder<T>, 'getResult' | 'getSingleResult' | 'getResultList' | 'where'> {
276
- where(cond: QBFilterQuery<T> | string, params?: keyof typeof GroupOperator | any[], operator?: keyof typeof GroupOperator): this;
277
- execute<U = QueryResult<T>>(method?: 'all' | 'get' | 'run', mapResults?: boolean): Promise<U>;
278
- then<TResult1 = QueryResult<T>, TResult2 = never>(onfulfilled?: ((value: QueryResult<T>) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<QueryResult<T>>;
295
+ export interface RunQueryBuilder<Entity extends object> extends Omit<QueryBuilder<Entity, any, any>, 'getResult' | 'getSingleResult' | 'getResultList' | 'where'> {
296
+ where(cond: QBFilterQuery<Entity> | string, params?: keyof typeof GroupOperator | any[], operator?: keyof typeof GroupOperator): this;
297
+ execute<Result = QueryResult<Entity>>(method?: 'all' | 'get' | 'run', mapResults?: boolean): Promise<Result>;
298
+ then<TResult1 = QueryResult<Entity>, TResult2 = never>(onfulfilled?: ((value: QueryResult<Entity>) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<QueryResult<Entity>>;
279
299
  }
280
- export interface SelectQueryBuilder<T extends object> extends QueryBuilder<T> {
281
- execute<U = T[]>(method?: 'all' | 'get' | 'run', mapResults?: boolean): Promise<U>;
282
- execute<U = T[]>(method: 'all', mapResults?: boolean): Promise<U>;
283
- execute<U = T>(method: 'get', mapResults?: boolean): Promise<U>;
284
- execute<U = QueryResult<T>>(method: 'run', mapResults?: boolean): Promise<U>;
285
- then<TResult1 = T[], TResult2 = never>(onfulfilled?: ((value: T[]) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<T[]>;
300
+ 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> {
301
+ execute<Result = Entity[]>(method?: 'all' | 'get' | 'run', mapResults?: boolean): Promise<Result>;
302
+ execute<Result = Entity[]>(method: 'all', mapResults?: boolean): Promise<Result>;
303
+ execute<Result = Entity>(method: 'get', mapResults?: boolean): Promise<Result>;
304
+ execute<Result = QueryResult<Entity>>(method: 'run', mapResults?: boolean): Promise<Result>;
305
+ then<TResult1 = Entity[], TResult2 = never>(onfulfilled?: ((value: Loaded<Entity, Hint>[]) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<Loaded<Entity, Hint>[]>;
286
306
  }
287
- export interface CountQueryBuilder<T extends object> extends QueryBuilder<T> {
288
- execute<U = {
307
+ export interface CountQueryBuilder<Entity extends object> extends QueryBuilder<Entity, any, any> {
308
+ execute<Result = {
289
309
  count: number;
290
- }[]>(method?: 'all' | 'get' | 'run', mapResults?: boolean): Promise<U>;
291
- execute<U = {
310
+ }[]>(method?: 'all' | 'get' | 'run', mapResults?: boolean): Promise<Result>;
311
+ execute<Result = {
292
312
  count: number;
293
- }[]>(method: 'all', mapResults?: boolean): Promise<U>;
294
- execute<U = {
313
+ }[]>(method: 'all', mapResults?: boolean): Promise<Result>;
314
+ execute<Result = {
295
315
  count: number;
296
- }>(method: 'get', mapResults?: boolean): Promise<U>;
297
- execute<U = QueryResult<{
316
+ }>(method: 'get', mapResults?: boolean): Promise<Result>;
317
+ execute<Result = QueryResult<{
298
318
  count: number;
299
- }>>(method: 'run', mapResults?: boolean): Promise<U>;
319
+ }>>(method: 'run', mapResults?: boolean): Promise<Result>;
300
320
  then<TResult1 = number, TResult2 = never>(onfulfilled?: ((value: number) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<number>;
301
321
  }
302
322
  export interface InsertQueryBuilder<T extends object> extends RunQueryBuilder<T> {
@@ -307,3 +327,4 @@ export interface DeleteQueryBuilder<T extends object> extends RunQueryBuilder<T>
307
327
  }
308
328
  export interface TruncateQueryBuilder<T extends object> extends RunQueryBuilder<T> {
309
329
  }
330
+ export {};