@mikro-orm/knex 6.0.0-dev.13 → 6.0.0-dev.130
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AbstractSqlConnection.d.ts +8 -4
- package/AbstractSqlConnection.js +30 -18
- package/AbstractSqlDriver.d.ts +21 -23
- package/AbstractSqlDriver.js +393 -224
- package/AbstractSqlPlatform.d.ts +5 -4
- package/AbstractSqlPlatform.js +34 -5
- package/MonkeyPatchable.d.ts +1 -0
- package/MonkeyPatchable.js +3 -0
- package/PivotCollectionPersister.d.ts +17 -0
- package/PivotCollectionPersister.js +128 -0
- package/README.md +64 -107
- package/SqlEntityManager.d.ts +2 -6
- package/SqlEntityManager.js +5 -9
- package/SqlEntityRepository.d.ts +7 -6
- package/SqlEntityRepository.js +11 -8
- package/index.mjs +24 -6
- package/package.json +8 -8
- package/query/ArrayCriteriaNode.d.ts +3 -3
- package/query/CriteriaNode.d.ts +8 -8
- package/query/CriteriaNode.js +16 -9
- package/query/CriteriaNodeFactory.d.ts +6 -6
- package/query/CriteriaNodeFactory.js +17 -13
- package/query/ObjectCriteriaNode.d.ts +3 -3
- package/query/ObjectCriteriaNode.js +14 -10
- package/query/QueryBuilder.d.ts +49 -21
- package/query/QueryBuilder.js +388 -132
- package/query/QueryBuilderHelper.d.ts +11 -16
- package/query/QueryBuilderHelper.js +194 -155
- package/query/ScalarCriteriaNode.d.ts +3 -2
- package/query/ScalarCriteriaNode.js +10 -6
- package/query/enums.d.ts +7 -0
- package/query/enums.js +10 -2
- package/schema/DatabaseSchema.d.ts +5 -2
- package/schema/DatabaseSchema.js +27 -9
- package/schema/DatabaseTable.d.ts +4 -2
- package/schema/DatabaseTable.js +67 -32
- package/schema/SchemaComparator.d.ts +3 -3
- package/schema/SchemaComparator.js +50 -30
- package/schema/SchemaHelper.d.ts +6 -4
- package/schema/SchemaHelper.js +18 -7
- package/schema/SqlSchemaGenerator.d.ts +3 -6
- package/schema/SqlSchemaGenerator.js +69 -34
- package/typings.d.ts +17 -10
package/query/QueryBuilder.d.ts
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { inspect } from 'util';
|
|
3
3
|
import type { Knex } from 'knex';
|
|
4
|
-
import type
|
|
5
|
-
import {
|
|
6
|
-
import { QueryType } from './enums';
|
|
4
|
+
import { type AnyEntity, type ConnectionType, type Dictionary, type EntityData, type EntityName, type EntityProperty, type FlushMode, type GroupOperator, LockMode, type LoggingOptions, type MetadataStorage, type ObjectQuery, PopulateHint, type PopulateOptions, type QBFilterQuery, type QBQueryOrderMap, QueryFlag, type QueryResult, type RequiredEntityData } from '@mikro-orm/core';
|
|
5
|
+
import { QueryType, JoinType } from './enums';
|
|
7
6
|
import type { AbstractSqlDriver } from '../AbstractSqlDriver';
|
|
8
|
-
import { QueryBuilderHelper } from './QueryBuilderHelper';
|
|
9
|
-
import type { Alias } from './QueryBuilderHelper';
|
|
7
|
+
import { type Alias, QueryBuilderHelper } from './QueryBuilderHelper';
|
|
10
8
|
import type { SqlEntityManager } from '../SqlEntityManager';
|
|
11
9
|
import type { Field } from '../typings';
|
|
10
|
+
import type { AbstractSqlPlatform } from '../AbstractSqlPlatform';
|
|
11
|
+
export interface ExecuteOptions {
|
|
12
|
+
mapResults?: boolean;
|
|
13
|
+
mergeResults?: boolean;
|
|
14
|
+
}
|
|
12
15
|
/**
|
|
13
16
|
* SQL query builder with fluent interface.
|
|
14
17
|
*
|
|
@@ -29,12 +32,14 @@ import type { Field } from '../typings';
|
|
|
29
32
|
* ```
|
|
30
33
|
*/
|
|
31
34
|
export declare class QueryBuilder<T extends object = AnyEntity> {
|
|
35
|
+
#private;
|
|
32
36
|
private readonly metadata;
|
|
33
37
|
private readonly driver;
|
|
34
38
|
private readonly context?;
|
|
35
39
|
private connectionType?;
|
|
36
40
|
private readonly em?;
|
|
37
|
-
|
|
41
|
+
private readonly logging?;
|
|
42
|
+
get mainAlias(): Alias<T>;
|
|
38
43
|
get alias(): string;
|
|
39
44
|
get helper(): QueryBuilderHelper;
|
|
40
45
|
/** @internal */
|
|
@@ -58,6 +63,7 @@ export declare class QueryBuilder<T extends object = AnyEntity> {
|
|
|
58
63
|
private _orderBy;
|
|
59
64
|
private _groupBy;
|
|
60
65
|
private _having;
|
|
66
|
+
private _returning?;
|
|
61
67
|
private _onConflict?;
|
|
62
68
|
private _limit?;
|
|
63
69
|
private _offset?;
|
|
@@ -65,6 +71,8 @@ export declare class QueryBuilder<T extends object = AnyEntity> {
|
|
|
65
71
|
private _joinedProps;
|
|
66
72
|
private _cache?;
|
|
67
73
|
private _indexHint?;
|
|
74
|
+
private _comments;
|
|
75
|
+
private _hintComments;
|
|
68
76
|
private flushMode?;
|
|
69
77
|
private lockMode?;
|
|
70
78
|
private lockTables?;
|
|
@@ -77,7 +85,7 @@ export declare class QueryBuilder<T extends object = AnyEntity> {
|
|
|
77
85
|
/**
|
|
78
86
|
* @internal
|
|
79
87
|
*/
|
|
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("
|
|
88
|
+
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, logging?: LoggingOptions | undefined);
|
|
81
89
|
select(fields: Field<T> | Field<T>[], distinct?: boolean): SelectQueryBuilder<T>;
|
|
82
90
|
addSelect(fields: Field<T> | Field<T>[]): SelectQueryBuilder<T>;
|
|
83
91
|
distinct(): SelectQueryBuilder<T>;
|
|
@@ -88,11 +96,17 @@ export declare class QueryBuilder<T extends object = AnyEntity> {
|
|
|
88
96
|
delete(cond?: QBFilterQuery): DeleteQueryBuilder<T>;
|
|
89
97
|
truncate(): TruncateQueryBuilder<T>;
|
|
90
98
|
count(field?: string | string[], distinct?: boolean): CountQueryBuilder<T>;
|
|
91
|
-
join(field: string
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
99
|
+
join(field: string | Knex.QueryBuilder | QueryBuilder<any>, alias: string, cond?: QBFilterQuery, type?: JoinType, path?: string, schema?: string): this;
|
|
100
|
+
innerJoin(field: string | Knex.QueryBuilder | QueryBuilder<any>, alias: string, cond?: QBFilterQuery, schema?: string): this;
|
|
101
|
+
innerJoinLateral(field: string | Knex.QueryBuilder | QueryBuilder<any>, alias: string, cond?: QBFilterQuery, schema?: string): this;
|
|
102
|
+
leftJoin(field: string | Knex.QueryBuilder | QueryBuilder<any>, alias: string, cond?: QBFilterQuery, schema?: string): this;
|
|
103
|
+
leftJoinLateral(field: string | Knex.QueryBuilder | QueryBuilder<any>, alias: string, cond?: QBFilterQuery, schema?: string): this;
|
|
104
|
+
joinAndSelect(field: string | [field: string, qb: Knex.QueryBuilder | QueryBuilder<any>], alias: string, cond?: QBFilterQuery, type?: JoinType, path?: string, fields?: string[], schema?: string): SelectQueryBuilder<T>;
|
|
105
|
+
leftJoinAndSelect(field: string | [field: string, qb: Knex.QueryBuilder | QueryBuilder<any>], alias: string, cond?: QBFilterQuery, fields?: string[], schema?: string): SelectQueryBuilder<T>;
|
|
106
|
+
leftJoinLateralAndSelect(field: string | [field: string, qb: Knex.QueryBuilder | QueryBuilder<any>], alias: string, cond?: QBFilterQuery, fields?: string[], schema?: string): SelectQueryBuilder<T>;
|
|
107
|
+
innerJoinAndSelect(field: string | [field: string, qb: Knex.QueryBuilder | QueryBuilder<any>], alias: string, cond?: QBFilterQuery, fields?: string[], schema?: string): SelectQueryBuilder<T>;
|
|
108
|
+
innerJoinLateralAndSelect(field: string | [field: string, qb: Knex.QueryBuilder | QueryBuilder<any>], alias: string, cond?: QBFilterQuery, fields?: string[], schema?: string): SelectQueryBuilder<T>;
|
|
109
|
+
protected getFieldsForJoinedLoad(prop: EntityProperty<T>, alias: string, explicitFields?: string[]): Field<T>[];
|
|
96
110
|
withSubQuery(subQuery: Knex.QueryBuilder, alias: string): this;
|
|
97
111
|
where(cond: QBFilterQuery<T>, operator?: keyof typeof GroupOperator): this;
|
|
98
112
|
where(cond: string, params?: any[], operator?: keyof typeof GroupOperator): this;
|
|
@@ -106,17 +120,11 @@ export declare class QueryBuilder<T extends object = AnyEntity> {
|
|
|
106
120
|
onConflict(fields?: Field<T> | Field<T>[]): this;
|
|
107
121
|
ignore(): this;
|
|
108
122
|
merge(data?: EntityData<T> | Field<T>[]): this;
|
|
123
|
+
returning(fields?: Field<T> | Field<T>[]): this;
|
|
109
124
|
/**
|
|
110
125
|
* @internal
|
|
111
126
|
*/
|
|
112
127
|
populate(populate: PopulateOptions<T>[], populateWhere?: ObjectQuery<T> | PopulateHint): this;
|
|
113
|
-
/**
|
|
114
|
-
* @internal
|
|
115
|
-
*/
|
|
116
|
-
ref(field: string): Knex.Ref<string, {
|
|
117
|
-
[x: string]: string;
|
|
118
|
-
}>;
|
|
119
|
-
raw<R = Knex.Raw>(sql: string, bindings?: Knex.RawBinding[] | Knex.ValueDict): R;
|
|
120
128
|
limit(limit?: number, offset?: number): this;
|
|
121
129
|
offset(offset?: number): this;
|
|
122
130
|
withSchema(schema?: string): this;
|
|
@@ -129,6 +137,16 @@ export declare class QueryBuilder<T extends object = AnyEntity> {
|
|
|
129
137
|
* Adds index hint to the FROM clause.
|
|
130
138
|
*/
|
|
131
139
|
indexHint(sql: string): this;
|
|
140
|
+
/**
|
|
141
|
+
* Prepend comment to the sql query using the syntax `/* ... *‍/`. Some characters are forbidden such as `/*, *‍/` and `?`.
|
|
142
|
+
*/
|
|
143
|
+
comment(comment: string | string[]): this;
|
|
144
|
+
/**
|
|
145
|
+
* Add hints to the query using comment-like syntax `/*+ ... *‍/`. MySQL and Oracle use this syntax for optimizer hints.
|
|
146
|
+
* Also various DB proxies and routers use this syntax to pass hints to alter their behavior. In other dialects the hints
|
|
147
|
+
* are ignored as simple comments.
|
|
148
|
+
*/
|
|
149
|
+
hintComment(comment: string | string[]): this;
|
|
132
150
|
/**
|
|
133
151
|
* Specifies FROM which entity's table select/update/delete will be executed, removing all previously set FROM-s.
|
|
134
152
|
* Allows setting a main string alias of the selection data.
|
|
@@ -140,6 +158,11 @@ export declare class QueryBuilder<T extends object = AnyEntity> {
|
|
|
140
158
|
* Returns the query with parameters as wildcards.
|
|
141
159
|
*/
|
|
142
160
|
getQuery(): string;
|
|
161
|
+
toQuery(): {
|
|
162
|
+
sql: string;
|
|
163
|
+
_sql: Knex.Sql;
|
|
164
|
+
params: readonly unknown[];
|
|
165
|
+
};
|
|
143
166
|
/**
|
|
144
167
|
* Returns the list of all parameters for this query.
|
|
145
168
|
*/
|
|
@@ -164,7 +187,7 @@ export declare class QueryBuilder<T extends object = AnyEntity> {
|
|
|
164
187
|
* Executes this QB and returns the raw results, mapped to the property names (unless disabled via last parameter).
|
|
165
188
|
* Use `method` to specify what kind of result you want to get (array/single/meta).
|
|
166
189
|
*/
|
|
167
|
-
execute<U = any>(method?: 'all' | 'get' | 'run',
|
|
190
|
+
execute<U = any>(method?: 'all' | 'get' | 'run', options?: ExecuteOptions | boolean): Promise<U>;
|
|
168
191
|
/**
|
|
169
192
|
* Alias for `qb.getResultList()`
|
|
170
193
|
*/
|
|
@@ -181,6 +204,10 @@ export declare class QueryBuilder<T extends object = AnyEntity> {
|
|
|
181
204
|
* Executes count query (without offset and limit), returning total count of results
|
|
182
205
|
*/
|
|
183
206
|
getCount(field?: string | string[], distinct?: boolean): Promise<number>;
|
|
207
|
+
/**
|
|
208
|
+
* Executes the query, returning both array of results and total count query (without offset and limit).
|
|
209
|
+
*/
|
|
210
|
+
getResultAndCount(): Promise<[T[], number]>;
|
|
184
211
|
/**
|
|
185
212
|
* Provides promise-like interface so we can await the QB instance.
|
|
186
213
|
*/
|
|
@@ -196,11 +223,12 @@ export declare class QueryBuilder<T extends object = AnyEntity> {
|
|
|
196
223
|
private prepareFields;
|
|
197
224
|
private init;
|
|
198
225
|
private getQueryBase;
|
|
226
|
+
private applyDiscriminatorCondition;
|
|
199
227
|
private finalize;
|
|
228
|
+
private processPopulateWhere;
|
|
200
229
|
private hasToManyJoins;
|
|
201
230
|
private wrapPaginateSubQuery;
|
|
202
231
|
private wrapModifySubQuery;
|
|
203
|
-
private autoJoinPivotTable;
|
|
204
232
|
private getSchema;
|
|
205
233
|
private createAlias;
|
|
206
234
|
private createMainAlias;
|