@mikro-orm/knex 6.0.0-dev.1 → 6.0.0-dev.11
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/{dist/AbstractSqlConnection.d.ts → AbstractSqlConnection.d.ts} +0 -0
- package/{dist/AbstractSqlConnection.js → AbstractSqlConnection.js} +5 -0
- package/AbstractSqlDriver.d.ts +66 -0
- package/{dist/AbstractSqlDriver.js → AbstractSqlDriver.js} +226 -70
- package/{dist/AbstractSqlPlatform.d.ts → AbstractSqlPlatform.d.ts} +7 -7
- package/{dist/AbstractSqlPlatform.js → AbstractSqlPlatform.js} +12 -14
- package/{dist/MonkeyPatchable.d.ts → MonkeyPatchable.d.ts} +0 -0
- package/{dist/MonkeyPatchable.js → MonkeyPatchable.js} +0 -0
- package/{dist/README.md → README.md} +2 -2
- package/{dist/SqlEntityManager.d.ts → SqlEntityManager.d.ts} +5 -5
- package/{dist/SqlEntityManager.js → SqlEntityManager.js} +0 -1
- package/{dist/SqlEntityRepository.d.ts → SqlEntityRepository.d.ts} +3 -3
- package/{dist/SqlEntityRepository.js → SqlEntityRepository.js} +1 -1
- package/{dist/index.d.ts → index.d.ts} +1 -0
- package/{dist/index.js → index.js} +6 -1
- package/index.mjs +192 -0
- package/package.json +18 -47
- package/{dist/query → query}/ArrayCriteriaNode.d.ts +0 -0
- package/{dist/query → query}/ArrayCriteriaNode.js +0 -0
- package/{dist/query → query}/CriteriaNode.d.ts +0 -0
- package/{dist/query → query}/CriteriaNode.js +7 -4
- package/{dist/query → query}/CriteriaNodeFactory.d.ts +0 -0
- package/{dist/query → query}/CriteriaNodeFactory.js +0 -0
- package/{dist/query → query}/ObjectCriteriaNode.d.ts +0 -0
- package/{dist/query → query}/ObjectCriteriaNode.js +14 -1
- package/{dist/query → query}/QueryBuilder.d.ts +61 -24
- package/{dist/query → query}/QueryBuilder.js +308 -84
- package/{dist/query → query}/QueryBuilderHelper.d.ts +19 -11
- package/{dist/query → query}/QueryBuilderHelper.js +206 -108
- package/{dist/query → query}/ScalarCriteriaNode.d.ts +0 -0
- package/{dist/query → query}/ScalarCriteriaNode.js +0 -0
- package/{dist/query → query}/enums.d.ts +0 -0
- package/{dist/query → query}/enums.js +0 -0
- package/{dist/query → query}/index.d.ts +0 -0
- package/{dist/query → query}/index.js +5 -1
- package/{dist/schema → schema}/DatabaseSchema.d.ts +1 -1
- package/{dist/schema → schema}/DatabaseSchema.js +8 -16
- package/{dist/schema → schema}/DatabaseTable.d.ts +8 -8
- package/{dist/schema → schema}/DatabaseTable.js +2 -1
- package/{dist/schema → schema}/SchemaComparator.d.ts +7 -5
- package/{dist/schema → schema}/SchemaComparator.js +58 -10
- package/{dist/schema → schema}/SchemaHelper.d.ts +15 -10
- package/{dist/schema → schema}/SchemaHelper.js +46 -8
- package/{dist/schema/SchemaGenerator.d.ts → schema/SqlSchemaGenerator.d.ts} +12 -12
- package/{dist/schema/SchemaGenerator.js → schema/SqlSchemaGenerator.js} +85 -34
- package/{dist/schema → schema}/index.d.ts +1 -1
- package/{dist/schema → schema}/index.js +6 -2
- package/{dist/typings.d.ts → typings.d.ts} +16 -12
- package/{dist/typings.js → typings.js} +0 -0
- package/CHANGELOG.md +0 -661
- package/dist/AbstractSqlDriver.d.ts +0 -55
- package/dist/LICENSE +0 -21
- package/dist/index.mjs +0 -26
- package/dist/package.json +0 -99
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { inspect } from 'util';
|
|
1
3
|
import type { Knex } from 'knex';
|
|
2
|
-
import type { AnyEntity, Dictionary, EntityData, EntityProperty,
|
|
3
|
-
import { LockMode, QueryFlag } from '@mikro-orm/core';
|
|
4
|
+
import type { AnyEntity, ConnectionType, Dictionary, EntityData, EntityName, EntityProperty, FlushMode, GroupOperator, MetadataStorage, ObjectQuery, PopulateOptions, QBFilterQuery, QBQueryOrderMap, QueryResult, RequiredEntityData } from '@mikro-orm/core';
|
|
5
|
+
import { LockMode, PopulateHint, QueryFlag } from '@mikro-orm/core';
|
|
4
6
|
import { QueryType } from './enums';
|
|
5
7
|
import type { AbstractSqlDriver } from '../AbstractSqlDriver';
|
|
8
|
+
import { QueryBuilderHelper } from './QueryBuilderHelper';
|
|
9
|
+
import type { Alias } from './QueryBuilderHelper';
|
|
6
10
|
import type { SqlEntityManager } from '../SqlEntityManager';
|
|
7
11
|
import type { Field } from '../typings';
|
|
8
12
|
/**
|
|
@@ -24,27 +28,30 @@ import type { Field } from '../typings';
|
|
|
24
28
|
* const publisher = await qb.getSingleResult();
|
|
25
29
|
* ```
|
|
26
30
|
*/
|
|
27
|
-
export declare class QueryBuilder<T extends
|
|
28
|
-
private readonly entityName;
|
|
31
|
+
export declare class QueryBuilder<T extends object = AnyEntity> {
|
|
29
32
|
private readonly metadata;
|
|
30
33
|
private readonly driver;
|
|
31
34
|
private readonly context?;
|
|
32
35
|
private connectionType?;
|
|
33
36
|
private readonly em?;
|
|
34
|
-
|
|
37
|
+
get mainAlias(): Alias;
|
|
38
|
+
get alias(): string;
|
|
39
|
+
get helper(): QueryBuilderHelper;
|
|
35
40
|
/** @internal */
|
|
36
|
-
type
|
|
41
|
+
type?: QueryType;
|
|
37
42
|
/** @internal */
|
|
38
43
|
_fields?: Field<T>[];
|
|
39
44
|
/** @internal */
|
|
40
45
|
_populate: PopulateOptions<T>[];
|
|
41
46
|
/** @internal */
|
|
47
|
+
_populateWhere?: ObjectQuery<T> | PopulateHint;
|
|
48
|
+
/** @internal */
|
|
42
49
|
_populateMap: Dictionary<string>;
|
|
43
50
|
private aliasCounter;
|
|
44
51
|
private flags;
|
|
45
52
|
private finalized;
|
|
46
53
|
private _joins;
|
|
47
|
-
private
|
|
54
|
+
private _explicitAlias;
|
|
48
55
|
private _schema?;
|
|
49
56
|
private _cond;
|
|
50
57
|
private _data;
|
|
@@ -54,6 +61,7 @@ export declare class QueryBuilder<T extends AnyEntity<T> = AnyEntity> {
|
|
|
54
61
|
private _onConflict?;
|
|
55
62
|
private _limit?;
|
|
56
63
|
private _offset?;
|
|
64
|
+
private _distinctOn?;
|
|
57
65
|
private _joinedProps;
|
|
58
66
|
private _cache?;
|
|
59
67
|
private _indexHint?;
|
|
@@ -61,16 +69,20 @@ export declare class QueryBuilder<T extends AnyEntity<T> = AnyEntity> {
|
|
|
61
69
|
private lockMode?;
|
|
62
70
|
private lockTables?;
|
|
63
71
|
private subQueries;
|
|
64
|
-
private
|
|
72
|
+
private _mainAlias?;
|
|
73
|
+
private _aliases;
|
|
74
|
+
private _helper?;
|
|
65
75
|
private readonly platform;
|
|
66
76
|
private readonly knex;
|
|
67
|
-
private readonly helper;
|
|
68
77
|
/**
|
|
69
78
|
* @internal
|
|
70
79
|
*/
|
|
71
|
-
constructor(entityName:
|
|
80
|
+
constructor(entityName: EntityName<T> | QueryBuilder<T>, metadata: MetadataStorage, driver: AbstractSqlDriver, context?: Knex.Transaction<any, any[]> | undefined, alias?: string, connectionType?: ConnectionType | undefined, em?: SqlEntityManager<AbstractSqlDriver<import("../AbstractSqlConnection").AbstractSqlConnection, import("../AbstractSqlPlatform").AbstractSqlPlatform>> | undefined);
|
|
72
81
|
select(fields: Field<T> | Field<T>[], distinct?: boolean): SelectQueryBuilder<T>;
|
|
73
82
|
addSelect(fields: Field<T> | Field<T>[]): SelectQueryBuilder<T>;
|
|
83
|
+
distinct(): SelectQueryBuilder<T>;
|
|
84
|
+
/** postgres only */
|
|
85
|
+
distinctOn(fields: string | string[]): SelectQueryBuilder<T>;
|
|
74
86
|
insert(data: RequiredEntityData<T> | RequiredEntityData<T>[]): InsertQueryBuilder<T>;
|
|
75
87
|
update(data: EntityData<T>): UpdateQueryBuilder<T>;
|
|
76
88
|
delete(cond?: QBFilterQuery): DeleteQueryBuilder<T>;
|
|
@@ -78,9 +90,9 @@ export declare class QueryBuilder<T extends AnyEntity<T> = AnyEntity> {
|
|
|
78
90
|
count(field?: string | string[], distinct?: boolean): CountQueryBuilder<T>;
|
|
79
91
|
join(field: string, alias: string, cond?: QBFilterQuery, type?: 'leftJoin' | 'innerJoin' | 'pivotJoin', path?: string): this;
|
|
80
92
|
leftJoin(field: string, alias: string, cond?: QBFilterQuery): this;
|
|
81
|
-
joinAndSelect(field: string, alias: string, cond?: QBFilterQuery, type?: 'leftJoin' | 'innerJoin' | 'pivotJoin', path?: string):
|
|
82
|
-
leftJoinAndSelect(field: string, alias: string, cond?: QBFilterQuery):
|
|
83
|
-
protected getFieldsForJoinedLoad<U extends
|
|
93
|
+
joinAndSelect(field: string, alias: string, cond?: QBFilterQuery, type?: 'leftJoin' | 'innerJoin' | 'pivotJoin', path?: string): SelectQueryBuilder<T>;
|
|
94
|
+
leftJoinAndSelect(field: string, alias: string, cond?: QBFilterQuery): SelectQueryBuilder<T>;
|
|
95
|
+
protected getFieldsForJoinedLoad<U extends object>(prop: EntityProperty<U>, alias: string): Field<U>[];
|
|
84
96
|
withSubQuery(subQuery: Knex.QueryBuilder, alias: string): this;
|
|
85
97
|
where(cond: QBFilterQuery<T>, operator?: keyof typeof GroupOperator): this;
|
|
86
98
|
where(cond: string, params?: any[], operator?: keyof typeof GroupOperator): this;
|
|
@@ -88,16 +100,16 @@ export declare class QueryBuilder<T extends AnyEntity<T> = AnyEntity> {
|
|
|
88
100
|
andWhere(cond: string, params?: any[]): this;
|
|
89
101
|
orWhere(cond: QBFilterQuery<T>): this;
|
|
90
102
|
orWhere(cond: string, params?: any[]): this;
|
|
91
|
-
orderBy(orderBy:
|
|
103
|
+
orderBy(orderBy: QBQueryOrderMap<T> | QBQueryOrderMap<T>[]): this;
|
|
92
104
|
groupBy(fields: (string | keyof T) | readonly (string | keyof T)[]): this;
|
|
93
105
|
having(cond?: QBFilterQuery | string, params?: any[]): this;
|
|
94
|
-
onConflict(fields?:
|
|
106
|
+
onConflict(fields?: Field<T> | Field<T>[]): this;
|
|
95
107
|
ignore(): this;
|
|
96
108
|
merge(data?: EntityData<T> | Field<T>[]): this;
|
|
97
109
|
/**
|
|
98
110
|
* @internal
|
|
99
111
|
*/
|
|
100
|
-
populate(populate: PopulateOptions<T>[]): this;
|
|
112
|
+
populate(populate: PopulateOptions<T>[], populateWhere?: ObjectQuery<T> | PopulateHint): this;
|
|
101
113
|
/**
|
|
102
114
|
* @internal
|
|
103
115
|
*/
|
|
@@ -117,6 +129,12 @@ export declare class QueryBuilder<T extends AnyEntity<T> = AnyEntity> {
|
|
|
117
129
|
* Adds index hint to the FROM clause.
|
|
118
130
|
*/
|
|
119
131
|
indexHint(sql: string): this;
|
|
132
|
+
/**
|
|
133
|
+
* Specifies FROM which entity's table select/update/delete will be executed, removing all previously set FROM-s.
|
|
134
|
+
* Allows setting a main string alias of the selection data.
|
|
135
|
+
*/
|
|
136
|
+
from<T extends AnyEntity<T> = AnyEntity>(target: QueryBuilder<T>, aliasName?: string): QueryBuilder<T>;
|
|
137
|
+
from<T extends AnyEntity<T> = AnyEntity>(target: EntityName<T>): QueryBuilder<T>;
|
|
120
138
|
getKnexQuery(): Knex.QueryBuilder;
|
|
121
139
|
/**
|
|
122
140
|
* Returns the query with parameters as wildcards.
|
|
@@ -130,8 +148,18 @@ export declare class QueryBuilder<T extends AnyEntity<T> = AnyEntity> {
|
|
|
130
148
|
* Returns raw interpolated query string with all the parameters inlined.
|
|
131
149
|
*/
|
|
132
150
|
getFormattedQuery(): string;
|
|
151
|
+
/**
|
|
152
|
+
* @internal
|
|
153
|
+
*/
|
|
133
154
|
getAliasForJoinPath(path?: string): string | undefined;
|
|
155
|
+
/**
|
|
156
|
+
* @internal
|
|
157
|
+
*/
|
|
134
158
|
getNextAlias(entityName?: string): string;
|
|
159
|
+
/**
|
|
160
|
+
* @internal
|
|
161
|
+
*/
|
|
162
|
+
getAliasMap(): Dictionary<string>;
|
|
135
163
|
/**
|
|
136
164
|
* Executes this QB and returns the raw results, mapped to the property names (unless disabled via last parameter).
|
|
137
165
|
* Use `method` to specify what kind of result you want to get (array/single/meta).
|
|
@@ -157,7 +185,6 @@ export declare class QueryBuilder<T extends AnyEntity<T> = AnyEntity> {
|
|
|
157
185
|
* Provides promise-like interface so we can await the QB instance.
|
|
158
186
|
*/
|
|
159
187
|
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>>;
|
|
160
|
-
private getInnerPromise;
|
|
161
188
|
/**
|
|
162
189
|
* Returns knex instance with sub-query aliased with given alias.
|
|
163
190
|
* You can provide `EntityName.propName` as alias, then the field name will be used based on the metadata
|
|
@@ -170,23 +197,33 @@ export declare class QueryBuilder<T extends AnyEntity<T> = AnyEntity> {
|
|
|
170
197
|
private init;
|
|
171
198
|
private getQueryBase;
|
|
172
199
|
private finalize;
|
|
200
|
+
private hasToManyJoins;
|
|
173
201
|
private wrapPaginateSubQuery;
|
|
174
202
|
private wrapModifySubQuery;
|
|
175
203
|
private autoJoinPivotTable;
|
|
204
|
+
private getSchema;
|
|
205
|
+
private createAlias;
|
|
206
|
+
private createMainAlias;
|
|
207
|
+
private fromSubQuery;
|
|
208
|
+
private fromEntityName;
|
|
209
|
+
private createQueryBuilderHelper;
|
|
210
|
+
private ensureFromClause;
|
|
211
|
+
private ensureNotFinalized;
|
|
212
|
+
[inspect.custom](depth: number): string;
|
|
176
213
|
}
|
|
177
|
-
export interface RunQueryBuilder<T> extends Omit<QueryBuilder<T>, 'getResult' | 'getSingleResult' | 'getResultList' | 'where'> {
|
|
214
|
+
export interface RunQueryBuilder<T extends object> extends Omit<QueryBuilder<T>, 'getResult' | 'getSingleResult' | 'getResultList' | 'where'> {
|
|
178
215
|
where(cond: QBFilterQuery<T> | string, params?: keyof typeof GroupOperator | any[], operator?: keyof typeof GroupOperator): this;
|
|
179
216
|
execute<U = QueryResult<T>>(method?: 'all' | 'get' | 'run', mapResults?: boolean): Promise<U>;
|
|
180
217
|
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>>;
|
|
181
218
|
}
|
|
182
|
-
export interface SelectQueryBuilder<T> extends QueryBuilder<T> {
|
|
219
|
+
export interface SelectQueryBuilder<T extends object> extends QueryBuilder<T> {
|
|
183
220
|
execute<U = T[]>(method?: 'all' | 'get' | 'run', mapResults?: boolean): Promise<U>;
|
|
184
221
|
execute<U = T[]>(method: 'all', mapResults?: boolean): Promise<U>;
|
|
185
222
|
execute<U = T>(method: 'get', mapResults?: boolean): Promise<U>;
|
|
186
223
|
execute<U = QueryResult<T>>(method: 'run', mapResults?: boolean): Promise<U>;
|
|
187
224
|
then<TResult1 = T[], TResult2 = never>(onfulfilled?: ((value: T[]) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<T[]>;
|
|
188
225
|
}
|
|
189
|
-
export interface CountQueryBuilder<T> extends QueryBuilder<T> {
|
|
226
|
+
export interface CountQueryBuilder<T extends object> extends QueryBuilder<T> {
|
|
190
227
|
execute<U = {
|
|
191
228
|
count: number;
|
|
192
229
|
}[]>(method?: 'all' | 'get' | 'run', mapResults?: boolean): Promise<U>;
|
|
@@ -201,11 +238,11 @@ export interface CountQueryBuilder<T> extends QueryBuilder<T> {
|
|
|
201
238
|
}>>(method: 'run', mapResults?: boolean): Promise<U>;
|
|
202
239
|
then<TResult1 = number, TResult2 = never>(onfulfilled?: ((value: number) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<number>;
|
|
203
240
|
}
|
|
204
|
-
export interface InsertQueryBuilder<T> extends RunQueryBuilder<T> {
|
|
241
|
+
export interface InsertQueryBuilder<T extends object> extends RunQueryBuilder<T> {
|
|
205
242
|
}
|
|
206
|
-
export interface UpdateQueryBuilder<T> extends RunQueryBuilder<T> {
|
|
243
|
+
export interface UpdateQueryBuilder<T extends object> extends RunQueryBuilder<T> {
|
|
207
244
|
}
|
|
208
|
-
export interface DeleteQueryBuilder<T> extends RunQueryBuilder<T> {
|
|
245
|
+
export interface DeleteQueryBuilder<T extends object> extends RunQueryBuilder<T> {
|
|
209
246
|
}
|
|
210
|
-
export interface TruncateQueryBuilder<T> extends RunQueryBuilder<T> {
|
|
247
|
+
export interface TruncateQueryBuilder<T extends object> extends RunQueryBuilder<T> {
|
|
211
248
|
}
|