@mikro-orm/sql 7.0.0-dev.99 → 7.0.0-rc.1
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 +2 -4
- package/AbstractSqlConnection.js +3 -7
- package/AbstractSqlDriver.d.ts +89 -23
- package/AbstractSqlDriver.js +630 -197
- package/AbstractSqlPlatform.d.ts +11 -5
- package/AbstractSqlPlatform.js +18 -5
- package/PivotCollectionPersister.d.ts +5 -0
- package/PivotCollectionPersister.js +30 -12
- package/SqlEntityManager.d.ts +2 -2
- package/dialects/mysql/{MySqlPlatform.d.ts → BaseMySqlPlatform.d.ts} +4 -3
- package/dialects/mysql/{MySqlPlatform.js → BaseMySqlPlatform.js} +9 -4
- package/dialects/mysql/MySqlSchemaHelper.d.ts +12 -1
- package/dialects/mysql/MySqlSchemaHelper.js +97 -6
- package/dialects/mysql/index.d.ts +1 -2
- package/dialects/mysql/index.js +1 -2
- package/dialects/postgresql/BasePostgreSqlPlatform.d.ts +106 -0
- package/dialects/postgresql/BasePostgreSqlPlatform.js +350 -0
- package/dialects/postgresql/FullTextType.d.ts +14 -0
- package/dialects/postgresql/FullTextType.js +59 -0
- package/dialects/postgresql/PostgreSqlExceptionConverter.d.ts +8 -0
- package/dialects/postgresql/PostgreSqlExceptionConverter.js +47 -0
- package/dialects/postgresql/PostgreSqlSchemaHelper.d.ts +90 -0
- package/dialects/postgresql/PostgreSqlSchemaHelper.js +732 -0
- package/dialects/postgresql/index.d.ts +3 -0
- package/dialects/postgresql/index.js +3 -0
- package/dialects/sqlite/BaseSqliteConnection.d.ts +1 -0
- package/dialects/sqlite/BaseSqliteConnection.js +13 -0
- package/dialects/sqlite/BaseSqlitePlatform.d.ts +6 -0
- package/dialects/sqlite/BaseSqlitePlatform.js +12 -0
- package/dialects/sqlite/SqliteSchemaHelper.d.ts +25 -0
- package/dialects/sqlite/SqliteSchemaHelper.js +145 -19
- package/dialects/sqlite/index.d.ts +0 -1
- package/dialects/sqlite/index.js +0 -1
- package/package.json +5 -6
- package/plugin/transformer.d.ts +1 -1
- package/plugin/transformer.js +1 -1
- package/query/CriteriaNode.d.ts +9 -5
- package/query/CriteriaNode.js +16 -15
- package/query/CriteriaNodeFactory.d.ts +6 -6
- package/query/CriteriaNodeFactory.js +33 -31
- package/query/NativeQueryBuilder.d.ts +3 -2
- package/query/NativeQueryBuilder.js +1 -2
- package/query/ObjectCriteriaNode.js +51 -36
- package/query/QueryBuilder.d.ts +569 -79
- package/query/QueryBuilder.js +614 -171
- package/query/QueryBuilderHelper.d.ts +24 -16
- package/query/QueryBuilderHelper.js +167 -78
- package/query/ScalarCriteriaNode.js +2 -2
- package/query/raw.d.ts +11 -3
- package/query/raw.js +1 -2
- package/schema/DatabaseSchema.d.ts +15 -2
- package/schema/DatabaseSchema.js +143 -15
- package/schema/DatabaseTable.d.ts +12 -0
- package/schema/DatabaseTable.js +91 -31
- package/schema/SchemaComparator.d.ts +8 -0
- package/schema/SchemaComparator.js +127 -3
- package/schema/SchemaHelper.d.ts +26 -3
- package/schema/SchemaHelper.js +98 -11
- package/schema/SqlSchemaGenerator.d.ts +10 -0
- package/schema/SqlSchemaGenerator.js +137 -9
- package/tsconfig.build.tsbuildinfo +1 -0
- package/typings.d.ts +78 -38
- package/dialects/postgresql/PostgreSqlTableCompiler.d.ts +0 -1
- package/dialects/postgresql/PostgreSqlTableCompiler.js +0 -1
package/typings.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Generated, Kysely } from 'kysely';
|
|
2
|
-
import type {
|
|
2
|
+
import type { CheckCallback, DeferMode, Dictionary, EntityName, EntityProperty, EntitySchemaWithMeta, FilterQuery, GroupOperator, IndexColumnOptions, Opt, Primary, PrimaryProperty, QueryFlag, QueryOrderMap, RawQueryFragment, Type } from '@mikro-orm/core';
|
|
3
3
|
import type { JoinType, QueryType } from './query/enums.js';
|
|
4
4
|
import type { DatabaseSchema } from './schema/DatabaseSchema.js';
|
|
5
5
|
import type { DatabaseTable } from './schema/DatabaseTable.js';
|
|
@@ -11,8 +11,8 @@ export interface Table {
|
|
|
11
11
|
schema_name?: string;
|
|
12
12
|
table_comment?: string;
|
|
13
13
|
}
|
|
14
|
-
|
|
15
|
-
export type
|
|
14
|
+
/** @internal */
|
|
15
|
+
export type InternalField<T> = string | RawQueryFragment | QueryBuilder | NativeQueryBuilder;
|
|
16
16
|
export interface JoinOptions {
|
|
17
17
|
table: string;
|
|
18
18
|
schema?: string;
|
|
@@ -78,6 +78,29 @@ export interface IndexDef {
|
|
|
78
78
|
predicate?: string;
|
|
79
79
|
}>;
|
|
80
80
|
deferMode?: DeferMode | `${DeferMode}`;
|
|
81
|
+
/**
|
|
82
|
+
* Advanced column options for the index.
|
|
83
|
+
* When specified, these options override the simple columnNames for index generation.
|
|
84
|
+
*/
|
|
85
|
+
columns?: IndexColumnOptions[];
|
|
86
|
+
/**
|
|
87
|
+
* Columns to include in the index but not as part of the key (PostgreSQL, MSSQL).
|
|
88
|
+
*/
|
|
89
|
+
include?: string[];
|
|
90
|
+
/** Fill factor for the index as a percentage 0-100 (PostgreSQL, MSSQL). */
|
|
91
|
+
fillFactor?: number;
|
|
92
|
+
/**
|
|
93
|
+
* Whether the index is invisible/hidden from the query optimizer (MySQL 8+, MariaDB 10.6+, MongoDB).
|
|
94
|
+
*/
|
|
95
|
+
invisible?: boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Whether the index is disabled (MSSQL only).
|
|
98
|
+
*/
|
|
99
|
+
disabled?: boolean;
|
|
100
|
+
/**
|
|
101
|
+
* Whether the index should be clustered (MariaDB, MSSQL).
|
|
102
|
+
*/
|
|
103
|
+
clustered?: boolean;
|
|
81
104
|
}
|
|
82
105
|
export interface CheckDef<T = unknown> {
|
|
83
106
|
name: string;
|
|
@@ -111,6 +134,15 @@ export interface TableDifference {
|
|
|
111
134
|
changedForeignKeys: Dictionary<ForeignKey>;
|
|
112
135
|
removedForeignKeys: Dictionary<ForeignKey>;
|
|
113
136
|
}
|
|
137
|
+
export interface DatabaseView {
|
|
138
|
+
name: string;
|
|
139
|
+
schema?: string;
|
|
140
|
+
definition: string;
|
|
141
|
+
/** True if this is a materialized view (PostgreSQL only). */
|
|
142
|
+
materialized?: boolean;
|
|
143
|
+
/** For materialized views, whether data was populated on creation. */
|
|
144
|
+
withData?: boolean;
|
|
145
|
+
}
|
|
114
146
|
export interface SchemaDifference {
|
|
115
147
|
newNamespaces: Set<string>;
|
|
116
148
|
newNativeEnums: {
|
|
@@ -121,6 +153,12 @@ export interface SchemaDifference {
|
|
|
121
153
|
newTables: Dictionary<DatabaseTable>;
|
|
122
154
|
changedTables: Dictionary<TableDifference>;
|
|
123
155
|
removedTables: Dictionary<DatabaseTable>;
|
|
156
|
+
newViews: Dictionary<DatabaseView>;
|
|
157
|
+
changedViews: Dictionary<{
|
|
158
|
+
from: DatabaseView;
|
|
159
|
+
to: DatabaseView;
|
|
160
|
+
}>;
|
|
161
|
+
removedViews: Dictionary<DatabaseView>;
|
|
124
162
|
removedNamespaces: Set<string>;
|
|
125
163
|
removedNativeEnums: {
|
|
126
164
|
name: string;
|
|
@@ -132,54 +170,54 @@ export interface SchemaDifference {
|
|
|
132
170
|
export interface IQueryBuilder<T> {
|
|
133
171
|
readonly alias: string;
|
|
134
172
|
readonly type: QueryType;
|
|
135
|
-
|
|
173
|
+
/** @internal */
|
|
174
|
+
_fields?: InternalField<T>[];
|
|
136
175
|
/** @internal */
|
|
137
176
|
helper: any;
|
|
138
|
-
select(fields:
|
|
177
|
+
select(fields: string | RawQueryFragment | (string | RawQueryFragment)[], distinct?: boolean): this;
|
|
139
178
|
addSelect(fields: string | string[]): this;
|
|
140
|
-
from<T extends
|
|
179
|
+
from<T extends object>(target: EntityName<T> | IQueryBuilder<T>, aliasName?: string): IQueryBuilder<T>;
|
|
141
180
|
insert(data: any): this;
|
|
142
181
|
update(data: any): this;
|
|
143
|
-
delete(cond?:
|
|
182
|
+
delete(cond?: FilterQuery<any>): this;
|
|
144
183
|
truncate(): this;
|
|
145
184
|
count(field?: string | string[], distinct?: boolean): this;
|
|
146
|
-
join(field: string, alias: string, cond?:
|
|
147
|
-
innerJoin(field: string, alias: string, cond?:
|
|
148
|
-
leftJoin(field: string, alias: string, cond?:
|
|
149
|
-
joinAndSelect(field:
|
|
150
|
-
leftJoinAndSelect(field:
|
|
151
|
-
innerJoinAndSelect(field:
|
|
185
|
+
join(field: string, alias: string, cond?: FilterQuery<any>, type?: JoinType, path?: string): this;
|
|
186
|
+
innerJoin(field: string, alias: string, cond?: FilterQuery<any>): this;
|
|
187
|
+
leftJoin(field: string, alias: string, cond?: FilterQuery<any>): this;
|
|
188
|
+
joinAndSelect(field: any, alias: string, cond?: FilterQuery<any>): this;
|
|
189
|
+
leftJoinAndSelect(field: any, alias: string, cond?: FilterQuery<any>, fields?: string[]): this;
|
|
190
|
+
innerJoinAndSelect(field: any, alias: string, cond?: FilterQuery<any>, fields?: string[]): this;
|
|
152
191
|
withSubQuery(subQuery: RawQueryFragment | NativeQueryBuilder, alias: string): this;
|
|
153
|
-
where(cond:
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
andWhere(cond: string, params?: any[]): this;
|
|
157
|
-
orWhere(cond: QBFilterQuery<T>): this;
|
|
158
|
-
orWhere(cond: string, params?: any[]): this;
|
|
192
|
+
where(cond: FilterQuery<T> | string | RawQueryFragment | Dictionary, operator?: keyof typeof GroupOperator | any[], operator2?: keyof typeof GroupOperator): this;
|
|
193
|
+
andWhere(cond: FilterQuery<T> | string | RawQueryFragment | Dictionary, params?: any[]): this;
|
|
194
|
+
orWhere(cond: FilterQuery<T> | string | RawQueryFragment | Dictionary, params?: any[]): this;
|
|
159
195
|
orderBy(orderBy: QueryOrderMap<T>): this;
|
|
160
196
|
groupBy(fields: (string | keyof T) | (string | keyof T)[]): this;
|
|
161
|
-
having(cond?:
|
|
197
|
+
having(cond?: FilterQuery<any> | string, params?: any[]): this;
|
|
162
198
|
getAliasForJoinPath(path: string, options?: ICriteriaNodeProcessOptions): string | undefined;
|
|
163
199
|
getJoinForPath(path?: string, options?: ICriteriaNodeProcessOptions): JoinOptions | undefined;
|
|
164
|
-
getNextAlias(entityName?: string): string;
|
|
165
|
-
clone(reset?: boolean): IQueryBuilder<T>;
|
|
200
|
+
getNextAlias(entityName?: string | EntityName<T>): string;
|
|
201
|
+
clone(reset?: boolean | string[], preserve?: string[]): IQueryBuilder<T>;
|
|
166
202
|
setFlag(flag: QueryFlag): this;
|
|
167
203
|
unsetFlag(flag: QueryFlag): this;
|
|
168
204
|
hasFlag(flag: QueryFlag): boolean;
|
|
169
205
|
scheduleFilterCheck(path: string): void;
|
|
206
|
+
withSchema(schema: string): this;
|
|
170
207
|
}
|
|
171
208
|
export interface ICriteriaNodeProcessOptions {
|
|
172
209
|
alias?: string;
|
|
173
210
|
matchPopulateJoins?: boolean;
|
|
174
211
|
ignoreBranching?: boolean;
|
|
175
212
|
preferNoBranch?: boolean;
|
|
176
|
-
type?: 'orderBy';
|
|
213
|
+
type?: 'orderBy' | 'having';
|
|
177
214
|
filter?: boolean;
|
|
215
|
+
parentPath?: string;
|
|
178
216
|
}
|
|
179
217
|
export interface ICriteriaNode<T extends object> {
|
|
180
|
-
readonly entityName:
|
|
218
|
+
readonly entityName: EntityName<T>;
|
|
181
219
|
readonly parent?: ICriteriaNode<T> | undefined;
|
|
182
|
-
readonly key?: string | undefined;
|
|
220
|
+
readonly key?: string | symbol | undefined;
|
|
183
221
|
readonly strict?: boolean;
|
|
184
222
|
payload: any;
|
|
185
223
|
prop?: EntityProperty;
|
|
@@ -189,23 +227,23 @@ export interface ICriteriaNode<T extends object> {
|
|
|
189
227
|
willAutoJoin(qb: IQueryBuilder<T>, alias?: string, options?: ICriteriaNodeProcessOptions): boolean;
|
|
190
228
|
shouldRename(payload: any): boolean;
|
|
191
229
|
renameFieldToPK<T>(qb: IQueryBuilder<T>, ownerAlias?: string): string;
|
|
192
|
-
getPath(
|
|
230
|
+
getPath(opts?: {
|
|
231
|
+
addIndex?: boolean;
|
|
232
|
+
}): string;
|
|
193
233
|
getPivotPath(path: string): string;
|
|
194
234
|
}
|
|
195
235
|
export type MaybeReturnType<T> = T extends (...args: any[]) => infer R ? R : T;
|
|
196
236
|
export type InferEntityProperties<Schema> = Schema extends EntitySchemaWithMeta<any, any, any, any, infer Properties> ? Properties : never;
|
|
197
237
|
export type InferKyselyDB<TEntities extends {
|
|
198
238
|
name: string;
|
|
199
|
-
}, TOptions extends MikroKyselyPluginOptions = {}> = MapValueAsTable<
|
|
239
|
+
}, TOptions extends MikroKyselyPluginOptions = {}> = MapValueAsTable<MapTableName<TEntities, TOptions>, TOptions>;
|
|
200
240
|
export type InferDBFromKysely<TKysely extends Kysely<any>> = TKysely extends Kysely<infer TDB> ? TDB : never;
|
|
201
|
-
type PreferStringLiteral<TCandidate, TFallback> = [
|
|
202
|
-
|
|
203
|
-
] extends [never] ? TFallback : string extends TCandidate ? TFallback : TCandidate extends string ? TCandidate : TFallback;
|
|
204
|
-
export type MapByName<T extends {
|
|
241
|
+
type PreferStringLiteral<TCandidate, TFallback> = [TCandidate] extends [never] ? TFallback : string extends TCandidate ? TFallback : TCandidate extends string ? TCandidate : TFallback;
|
|
242
|
+
export type MapTableName<T extends {
|
|
205
243
|
name: string;
|
|
206
244
|
tableName?: string;
|
|
207
|
-
}> = {
|
|
208
|
-
[P in T as PreferStringLiteral<NonNullable<P['tableName']>, P['name']>]: P;
|
|
245
|
+
}, TOptions extends MikroKyselyPluginOptions = {}> = {
|
|
246
|
+
[P in T as TOptions['tableNamingStrategy'] extends 'entity' ? P['name'] : PreferStringLiteral<NonNullable<P['tableName']>, P['name']>]: P;
|
|
209
247
|
};
|
|
210
248
|
export type MapValueAsTable<TMap extends Record<string, any>, TOptions extends MikroKyselyPluginOptions = {}> = {
|
|
211
249
|
[K in keyof TMap as TransformName<K, TOptions['tableNamingStrategy'] extends 'entity' ? 'entity' : 'underscore'>]: InferKyselyTable<TMap[K], TOptions>;
|
|
@@ -235,7 +273,9 @@ type MaybeJoinColumnName<TName extends string, TBuilder> = TBuilder extends {
|
|
|
235
273
|
owner: true;
|
|
236
274
|
};
|
|
237
275
|
} ? PrimaryProperty<Value> extends string ? `${TName}_${SnakeCase<PrimaryProperty<Value>>}` : never : TName;
|
|
238
|
-
export type SnakeCase<TName extends string> = TName extends `${infer
|
|
276
|
+
export type SnakeCase<TName extends string> = TName extends `${infer A}${infer B}${infer Rest}` ? IsUpperLetter<B> extends never ? `${Lowercase<A>}${SnakeCase<`${B}${Rest}`>}` : IsLowerLetter<A> extends never ? `${Lowercase<A>}${SnakeCase<`${B}${Rest}`>}` : `${Lowercase<A>}_${SnakeCase<`${B}${Rest}`>}` : Lowercase<TName>;
|
|
277
|
+
type IsLowerLetter<C extends string> = C extends Lowercase<C> ? (C extends Uppercase<C> ? never : C) : never;
|
|
278
|
+
type IsUpperLetter<C extends string> = C extends Uppercase<C> ? (C extends Lowercase<C> ? never : C) : never;
|
|
239
279
|
type InferColumnValue<TBuilder, TProcessOnCreate extends boolean> = TBuilder extends {
|
|
240
280
|
'~type'?: {
|
|
241
281
|
value: infer Value;
|
|
@@ -244,7 +284,7 @@ type InferColumnValue<TBuilder, TProcessOnCreate extends boolean> = TBuilder ext
|
|
|
244
284
|
} ? MaybeNever<MaybeGenerated<MaybeJoinKey<Value, TOptions>, TOptions, TProcessOnCreate>, TOptions> : never;
|
|
245
285
|
type MaybeGenerated<TValue, TOptions, TProcessOnCreate extends boolean> = TOptions extends {
|
|
246
286
|
nullable: true;
|
|
247
|
-
} ?
|
|
287
|
+
} ? TValue | null : TOptions extends {
|
|
248
288
|
autoincrement: true;
|
|
249
289
|
} ? Generated<TValue> : TOptions extends {
|
|
250
290
|
default: true;
|
|
@@ -262,9 +302,9 @@ type MaybeJoinKey<TValue, TOptions> = TOptions extends {
|
|
|
262
302
|
} ? UnwrapOpt<Primary<TValue>> : never : TValue;
|
|
263
303
|
type UnwrapOpt<TValue> = TValue extends Opt<infer OriginalValue> ? OriginalValue : TValue;
|
|
264
304
|
type MaybeNever<TValue, TOptions> = TOptions extends {
|
|
265
|
-
persist:
|
|
266
|
-
}
|
|
267
|
-
kind: 'm:n';
|
|
305
|
+
persist: false;
|
|
306
|
+
} | {
|
|
307
|
+
kind: 'm:n' | '1:m';
|
|
268
308
|
} ? never : TValue;
|
|
269
309
|
type ExcludeNever<TMap extends Record<string, any>> = {
|
|
270
310
|
[K in keyof TMap as TMap[K] extends never ? never : K]: TMap[K];
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|