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