@mikro-orm/core 7.0.4-dev.9 → 7.0.4

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.
Files changed (206) hide show
  1. package/EntityManager.d.ts +884 -583
  2. package/EntityManager.js +1922 -1895
  3. package/MikroORM.d.ts +103 -74
  4. package/MikroORM.js +178 -179
  5. package/README.md +1 -1
  6. package/cache/CacheAdapter.d.ts +36 -36
  7. package/cache/FileCacheAdapter.d.ts +30 -24
  8. package/cache/FileCacheAdapter.js +80 -78
  9. package/cache/GeneratedCacheAdapter.d.ts +18 -20
  10. package/cache/GeneratedCacheAdapter.js +30 -30
  11. package/cache/MemoryCacheAdapter.d.ts +18 -20
  12. package/cache/MemoryCacheAdapter.js +35 -36
  13. package/cache/NullCacheAdapter.d.ts +16 -16
  14. package/cache/NullCacheAdapter.js +24 -24
  15. package/connections/Connection.d.ts +95 -84
  16. package/connections/Connection.js +165 -168
  17. package/drivers/DatabaseDriver.d.ts +186 -80
  18. package/drivers/DatabaseDriver.js +450 -443
  19. package/drivers/IDatabaseDriver.d.ts +440 -301
  20. package/entity/BaseEntity.d.ts +120 -83
  21. package/entity/BaseEntity.js +43 -43
  22. package/entity/Collection.d.ts +212 -179
  23. package/entity/Collection.js +727 -721
  24. package/entity/EntityAssigner.d.ts +88 -77
  25. package/entity/EntityAssigner.js +231 -230
  26. package/entity/EntityFactory.d.ts +66 -54
  27. package/entity/EntityFactory.js +425 -383
  28. package/entity/EntityHelper.d.ts +34 -22
  29. package/entity/EntityHelper.js +280 -267
  30. package/entity/EntityIdentifier.d.ts +4 -4
  31. package/entity/EntityIdentifier.js +10 -10
  32. package/entity/EntityLoader.d.ts +98 -72
  33. package/entity/EntityLoader.js +753 -723
  34. package/entity/EntityRepository.d.ts +316 -201
  35. package/entity/EntityRepository.js +213 -213
  36. package/entity/PolymorphicRef.d.ts +5 -5
  37. package/entity/PolymorphicRef.js +10 -10
  38. package/entity/Reference.d.ts +126 -82
  39. package/entity/Reference.js +278 -274
  40. package/entity/WrappedEntity.d.ts +115 -72
  41. package/entity/WrappedEntity.js +168 -166
  42. package/entity/defineEntity.d.ts +1315 -636
  43. package/entity/defineEntity.js +527 -518
  44. package/entity/utils.d.ts +13 -3
  45. package/entity/utils.js +71 -73
  46. package/entity/validators.js +43 -43
  47. package/entity/wrap.js +8 -8
  48. package/enums.d.ts +258 -253
  49. package/enums.js +251 -252
  50. package/errors.d.ts +114 -72
  51. package/errors.js +350 -253
  52. package/events/EventManager.d.ts +26 -14
  53. package/events/EventManager.js +79 -77
  54. package/events/EventSubscriber.d.ts +29 -29
  55. package/events/TransactionEventBroadcaster.d.ts +15 -8
  56. package/events/TransactionEventBroadcaster.js +14 -14
  57. package/exceptions.d.ts +23 -40
  58. package/exceptions.js +35 -52
  59. package/hydration/Hydrator.d.ts +42 -17
  60. package/hydration/Hydrator.js +43 -43
  61. package/hydration/ObjectHydrator.d.ts +50 -17
  62. package/hydration/ObjectHydrator.js +481 -416
  63. package/index.d.ts +116 -2
  64. package/index.js +10 -1
  65. package/logging/DefaultLogger.d.ts +34 -32
  66. package/logging/DefaultLogger.js +86 -86
  67. package/logging/Logger.d.ts +41 -41
  68. package/logging/SimpleLogger.d.ts +13 -11
  69. package/logging/SimpleLogger.js +22 -22
  70. package/logging/colors.d.ts +6 -6
  71. package/logging/colors.js +11 -10
  72. package/logging/inspect.js +7 -7
  73. package/metadata/EntitySchema.d.ts +211 -127
  74. package/metadata/EntitySchema.js +397 -398
  75. package/metadata/MetadataDiscovery.d.ts +114 -114
  76. package/metadata/MetadataDiscovery.js +1951 -1863
  77. package/metadata/MetadataProvider.d.ts +24 -21
  78. package/metadata/MetadataProvider.js +82 -84
  79. package/metadata/MetadataStorage.d.ts +38 -32
  80. package/metadata/MetadataStorage.js +118 -118
  81. package/metadata/MetadataValidator.d.ts +39 -39
  82. package/metadata/MetadataValidator.js +381 -338
  83. package/metadata/discover-entities.d.ts +5 -2
  84. package/metadata/discover-entities.js +35 -27
  85. package/metadata/types.d.ts +615 -531
  86. package/naming-strategy/AbstractNamingStrategy.d.ts +54 -39
  87. package/naming-strategy/AbstractNamingStrategy.js +90 -85
  88. package/naming-strategy/EntityCaseNamingStrategy.d.ts +6 -6
  89. package/naming-strategy/EntityCaseNamingStrategy.js +22 -22
  90. package/naming-strategy/MongoNamingStrategy.d.ts +6 -6
  91. package/naming-strategy/MongoNamingStrategy.js +18 -18
  92. package/naming-strategy/NamingStrategy.d.ts +109 -99
  93. package/naming-strategy/UnderscoreNamingStrategy.d.ts +7 -7
  94. package/naming-strategy/UnderscoreNamingStrategy.js +21 -21
  95. package/not-supported.js +7 -4
  96. package/package.json +1 -1
  97. package/platforms/ExceptionConverter.d.ts +1 -1
  98. package/platforms/ExceptionConverter.js +4 -4
  99. package/platforms/Platform.d.ts +310 -299
  100. package/platforms/Platform.js +663 -636
  101. package/serialization/EntitySerializer.d.ts +49 -26
  102. package/serialization/EntitySerializer.js +224 -218
  103. package/serialization/EntityTransformer.d.ts +10 -6
  104. package/serialization/EntityTransformer.js +219 -217
  105. package/serialization/SerializationContext.d.ts +27 -23
  106. package/serialization/SerializationContext.js +105 -105
  107. package/types/ArrayType.d.ts +8 -8
  108. package/types/ArrayType.js +33 -33
  109. package/types/BigIntType.d.ts +17 -10
  110. package/types/BigIntType.js +37 -37
  111. package/types/BlobType.d.ts +3 -3
  112. package/types/BlobType.js +13 -13
  113. package/types/BooleanType.d.ts +4 -4
  114. package/types/BooleanType.js +12 -12
  115. package/types/CharacterType.d.ts +2 -2
  116. package/types/CharacterType.js +6 -6
  117. package/types/DateTimeType.d.ts +5 -5
  118. package/types/DateTimeType.js +15 -15
  119. package/types/DateType.d.ts +5 -5
  120. package/types/DateType.js +15 -15
  121. package/types/DecimalType.d.ts +7 -7
  122. package/types/DecimalType.js +26 -26
  123. package/types/DoubleType.d.ts +3 -3
  124. package/types/DoubleType.js +12 -12
  125. package/types/EnumArrayType.d.ts +5 -5
  126. package/types/EnumArrayType.js +24 -24
  127. package/types/EnumType.d.ts +3 -3
  128. package/types/EnumType.js +11 -11
  129. package/types/FloatType.d.ts +3 -3
  130. package/types/FloatType.js +9 -9
  131. package/types/IntegerType.d.ts +3 -3
  132. package/types/IntegerType.js +9 -9
  133. package/types/IntervalType.d.ts +4 -4
  134. package/types/IntervalType.js +12 -12
  135. package/types/JsonType.d.ts +8 -8
  136. package/types/JsonType.js +32 -32
  137. package/types/MediumIntType.d.ts +1 -1
  138. package/types/MediumIntType.js +3 -3
  139. package/types/SmallIntType.d.ts +3 -3
  140. package/types/SmallIntType.js +9 -9
  141. package/types/StringType.d.ts +4 -4
  142. package/types/StringType.js +12 -12
  143. package/types/TextType.d.ts +3 -3
  144. package/types/TextType.js +9 -9
  145. package/types/TimeType.d.ts +5 -5
  146. package/types/TimeType.js +17 -17
  147. package/types/TinyIntType.d.ts +3 -3
  148. package/types/TinyIntType.js +10 -10
  149. package/types/Type.d.ts +83 -79
  150. package/types/Type.js +82 -82
  151. package/types/Uint8ArrayType.d.ts +4 -4
  152. package/types/Uint8ArrayType.js +21 -21
  153. package/types/UnknownType.d.ts +4 -4
  154. package/types/UnknownType.js +12 -12
  155. package/types/UuidType.d.ts +5 -5
  156. package/types/UuidType.js +19 -19
  157. package/types/index.d.ts +75 -49
  158. package/types/index.js +52 -26
  159. package/typings.d.ts +1250 -737
  160. package/typings.js +244 -231
  161. package/unit-of-work/ChangeSet.d.ts +26 -26
  162. package/unit-of-work/ChangeSet.js +56 -56
  163. package/unit-of-work/ChangeSetComputer.d.ts +12 -12
  164. package/unit-of-work/ChangeSetComputer.js +178 -170
  165. package/unit-of-work/ChangeSetPersister.d.ts +63 -44
  166. package/unit-of-work/ChangeSetPersister.js +442 -421
  167. package/unit-of-work/CommitOrderCalculator.d.ts +40 -40
  168. package/unit-of-work/CommitOrderCalculator.js +89 -88
  169. package/unit-of-work/IdentityMap.d.ts +31 -31
  170. package/unit-of-work/IdentityMap.js +105 -105
  171. package/unit-of-work/UnitOfWork.d.ts +181 -141
  172. package/unit-of-work/UnitOfWork.js +1200 -1183
  173. package/utils/AbstractMigrator.d.ts +111 -91
  174. package/utils/AbstractMigrator.js +275 -275
  175. package/utils/AbstractSchemaGenerator.d.ts +43 -34
  176. package/utils/AbstractSchemaGenerator.js +121 -122
  177. package/utils/AsyncContext.d.ts +3 -3
  178. package/utils/AsyncContext.js +34 -35
  179. package/utils/Configuration.d.ts +852 -808
  180. package/utils/Configuration.js +359 -344
  181. package/utils/Cursor.d.ts +40 -22
  182. package/utils/Cursor.js +135 -127
  183. package/utils/DataloaderUtils.d.ts +58 -43
  184. package/utils/DataloaderUtils.js +203 -198
  185. package/utils/EntityComparator.d.ts +98 -81
  186. package/utils/EntityComparator.js +828 -728
  187. package/utils/NullHighlighter.d.ts +1 -1
  188. package/utils/NullHighlighter.js +3 -3
  189. package/utils/QueryHelper.d.ts +79 -51
  190. package/utils/QueryHelper.js +372 -361
  191. package/utils/RawQueryFragment.d.ts +50 -34
  192. package/utils/RawQueryFragment.js +107 -105
  193. package/utils/RequestContext.d.ts +32 -32
  194. package/utils/RequestContext.js +52 -53
  195. package/utils/TransactionContext.d.ts +16 -16
  196. package/utils/TransactionContext.js +27 -27
  197. package/utils/TransactionManager.d.ts +58 -58
  198. package/utils/TransactionManager.js +199 -197
  199. package/utils/Utils.d.ts +204 -145
  200. package/utils/Utils.js +812 -810
  201. package/utils/clone.js +104 -113
  202. package/utils/env-vars.js +90 -88
  203. package/utils/fs-utils.d.ts +15 -15
  204. package/utils/fs-utils.js +180 -181
  205. package/utils/upsert-utils.d.ts +20 -5
  206. package/utils/upsert-utils.js +114 -116
@@ -2,7 +2,32 @@ import { clone } from '../utils/clone.js';
2
2
  import { EntityRepository } from '../entity/EntityRepository.js';
3
3
  import { UnderscoreNamingStrategy } from '../naming-strategy/UnderscoreNamingStrategy.js';
4
4
  import { ExceptionConverter } from './ExceptionConverter.js';
5
- import { ArrayType, BigIntType, BlobType, BooleanType, CharacterType, DateTimeType, DateType, DecimalType, DoubleType, EnumType, FloatType, IntegerType, IntervalType, JsonType, MediumIntType, SmallIntType, StringType, TextType, TimeType, TinyIntType, Type, Uint8ArrayType, UnknownType, UuidType, } from '../types/index.js';
5
+ import {
6
+ ArrayType,
7
+ BigIntType,
8
+ BlobType,
9
+ BooleanType,
10
+ CharacterType,
11
+ DateTimeType,
12
+ DateType,
13
+ DecimalType,
14
+ DoubleType,
15
+ EnumType,
16
+ FloatType,
17
+ IntegerType,
18
+ IntervalType,
19
+ JsonType,
20
+ MediumIntType,
21
+ SmallIntType,
22
+ StringType,
23
+ TextType,
24
+ TimeType,
25
+ TinyIntType,
26
+ Type,
27
+ Uint8ArrayType,
28
+ UnknownType,
29
+ UuidType,
30
+ } from '../types/index.js';
6
31
  import { parseJsonSafe, Utils } from '../utils/Utils.js';
7
32
  import { ReferenceKind } from '../enums.js';
8
33
  import { Raw } from '../utils/RawQueryFragment.js';
@@ -10,642 +35,644 @@ import { Raw } from '../utils/RawQueryFragment.js';
10
35
  export const JsonProperty = Symbol('JsonProperty');
11
36
  /** Abstract base class providing database-specific behavior and SQL dialect differences. */
12
37
  export class Platform {
13
- exceptionConverter = new ExceptionConverter();
14
- config;
15
- namingStrategy;
16
- timezone;
17
- /** Whether this driver uses pivot tables for M:N relations (SQL drivers do, MongoDB does not). */
18
- usesPivotTable() {
19
- return false;
20
- }
21
- /** Whether this driver supports database transactions. */
22
- supportsTransactions() {
23
- return !this.config.get('disableTransactions');
24
- }
25
- /** Whether the driver wraps operations in implicit transactions by default. */
26
- usesImplicitTransactions() {
27
- return true;
28
- }
29
- /** Returns the default naming strategy constructor for this platform. */
30
- getNamingStrategy() {
31
- return UnderscoreNamingStrategy;
32
- }
33
- /** Whether the driver supports RETURNING clause (e.g. PostgreSQL). */
34
- usesReturningStatement() {
35
- return false;
36
- }
37
- /** Whether the driver supports OUTPUT clause (e.g. MSSQL). */
38
- usesOutputStatement() {
39
- return false;
40
- }
41
- /** Whether DELETE statements require explicit CASCADE keyword. */
42
- usesCascadeStatement() {
43
- return false;
44
- }
45
- /** for postgres native enums */
46
- supportsNativeEnums() {
47
- return false;
48
- }
49
- /** for postgres text enums (default) */
50
- usesEnumCheckConstraints() {
51
- return false;
52
- }
53
- /** Whether this platform supports materialized views. */
54
- supportsMaterializedViews() {
55
- return false;
56
- }
57
- /** Returns the schema helper instance for this platform, or undefined if not supported. */
58
- getSchemaHelper() {
59
- return undefined;
60
- }
61
- /** Whether the platform automatically creates indexes on foreign key columns. */
62
- indexForeignKeys() {
63
- return false;
64
- }
65
- /**
66
- * Whether or not the driver supports retuning list of created PKs back when multi-inserting
67
- */
68
- usesBatchInserts() {
69
- return true;
70
- }
71
- /**
72
- * Whether or not the driver supports updating many records at once
73
- */
74
- usesBatchUpdates() {
75
- return true;
76
- }
77
- /** Whether the platform supports the DEFAULT keyword in INSERT statements. */
78
- usesDefaultKeyword() {
79
- return true;
80
- }
81
- /**
82
- * Normalizes primary key wrapper to scalar value (e.g. mongodb's ObjectId to string)
83
- */
84
- normalizePrimaryKey(data) {
85
- return data;
86
- }
87
- /**
88
- * Converts scalar primary key representation to native driver wrapper (e.g. string to mongodb's ObjectId)
89
- */
90
- denormalizePrimaryKey(data) {
91
- return data;
92
- }
93
- /**
94
- * Returns the SQL specific for the platform to get the current timestamp
95
- */
96
- getCurrentTimestampSQL(length) {
97
- return 'current_timestamp' + (length ? `(${length})` : '');
98
- }
99
- /** Returns the SQL type declaration for datetime columns. */
100
- getDateTimeTypeDeclarationSQL(column) {
101
- return 'datetime' + (column.length ? `(${column.length})` : '');
102
- }
103
- /** Returns the default fractional seconds precision for datetime columns. */
104
- getDefaultDateTimeLength() {
105
- return 0;
106
- }
107
- /** Returns the default length for varchar columns. */
108
- getDefaultVarcharLength() {
109
- return 255;
110
- }
111
- /** Returns the default length for char columns. */
112
- getDefaultCharLength() {
113
- return 1;
114
- }
115
- /** Returns the SQL type declaration for date columns. */
116
- getDateTypeDeclarationSQL(length) {
117
- return 'date' + (length ? `(${length})` : '');
118
- }
119
- /** Returns the SQL type declaration for time columns. */
120
- getTimeTypeDeclarationSQL(length) {
121
- return 'time' + (length ? `(${length})` : '');
122
- }
123
- /** Returns the SQL operator used for regular expression matching. */
124
- getRegExpOperator(val, flags) {
125
- return 'regexp';
126
- }
127
- /** Builds the SQL clause and parameters for a regular expression condition. */
128
- mapRegExpCondition(mappedKey, value) {
129
- const operator = this.getRegExpOperator(value.$re, value.$flags);
130
- const quotedKey = this.quoteIdentifier(mappedKey);
131
- return { sql: `${quotedKey} ${operator} ?`, params: [value.$re] };
132
- }
133
- /** Converts a JavaScript RegExp into a platform-specific regex representation. */
134
- getRegExpValue(val) {
135
- if (val.flags.includes('i')) {
136
- return { $re: `(?i)${val.source}` };
137
- }
138
- return { $re: val.source };
139
- }
140
- /** Whether the given operator is allowed at the top level of a query condition. */
141
- isAllowedTopLevelOperator(operator) {
142
- return operator === '$not';
143
- }
144
- /** Converts a version field value for comparison in optimistic locking queries. */
145
- convertVersionValue(value, prop) {
146
- return value;
147
- }
148
- /** Returns the default fractional seconds precision for version timestamp columns. */
149
- getDefaultVersionLength() {
150
- return 3;
151
- }
152
- /** Whether the platform supports tuple comparison in WHERE clauses. */
153
- allowsComparingTuples() {
154
- return true;
155
- }
156
- /** Whether the given property maps to a bigint database column. */
157
- isBigIntProperty(prop) {
158
- return prop.columnTypes?.[0] === 'bigint';
159
- }
160
- /** Returns the default schema name for this platform (e.g. "public" for PostgreSQL). */
161
- getDefaultSchemaName() {
162
- return undefined;
163
- }
164
- /** Returns the SQL type declaration for boolean columns. */
165
- getBooleanTypeDeclarationSQL() {
166
- return 'boolean';
167
- }
168
- /** Returns the SQL type declaration for integer columns. */
169
- getIntegerTypeDeclarationSQL(column) {
170
- return 'int';
171
- }
172
- getSmallIntTypeDeclarationSQL(column) {
173
- return 'smallint';
174
- }
175
- getMediumIntTypeDeclarationSQL(column) {
176
- return 'mediumint';
177
- }
178
- getTinyIntTypeDeclarationSQL(column) {
179
- return 'tinyint';
180
- }
181
- getBigIntTypeDeclarationSQL(column) {
182
- return 'bigint';
183
- }
184
- getCharTypeDeclarationSQL(column) {
185
- return `char(${column.length ?? this.getDefaultCharLength()})`;
186
- }
187
- getVarcharTypeDeclarationSQL(column) {
188
- return `varchar(${column.length ?? this.getDefaultVarcharLength()})`;
189
- }
190
- getIntervalTypeDeclarationSQL(column) {
191
- return 'interval' + (column.length ? `(${column.length})` : '');
192
- }
193
- getTextTypeDeclarationSQL(_column) {
194
- return 'text';
195
- }
196
- getEnumTypeDeclarationSQL(column) {
197
- if (column.items?.every(item => typeof item === 'string')) {
198
- return `enum('${column.items.join("','")}')`;
199
- }
200
- return this.getTinyIntTypeDeclarationSQL(column);
201
- }
202
- getFloatDeclarationSQL() {
203
- return 'float';
204
- }
205
- getDoubleDeclarationSQL() {
206
- return 'double';
207
- }
208
- getDecimalTypeDeclarationSQL(column) {
209
- const precision = column.precision ?? 10;
210
- const scale = column.scale ?? 0;
211
- return `numeric(${precision},${scale})`;
212
- }
213
- getUuidTypeDeclarationSQL(column) {
214
- column.length ??= 36;
215
- return this.getVarcharTypeDeclarationSQL(column);
216
- }
217
- /** Extracts the base type name from a full SQL type declaration (e.g. "varchar(255)" -> "varchar"). */
218
- extractSimpleType(type) {
219
- return /[^(), ]+/.exec(type.toLowerCase())[0];
220
- }
221
- /**
222
- * This should be used only to compare types, it can strip some information like the length.
223
- */
224
- normalizeColumnType(type, options) {
225
- return type.toLowerCase();
226
- }
227
- /** Returns the mapped Type instance for a given SQL/runtime type string. */
228
- getMappedType(type) {
229
- const mappedType = this.config.get('discovery').getMappedType?.(type, this);
230
- return mappedType ?? this.getDefaultMappedType(type);
231
- }
232
- /** Returns the default mapped Type for a given type string when no custom mapping is configured. */
233
- getDefaultMappedType(type) {
234
- if (type.endsWith('[]')) {
235
- return Type.getType(ArrayType);
236
- }
237
- switch (this.extractSimpleType(type)) {
238
- case 'character':
239
- case 'char':
240
- return Type.getType(CharacterType);
241
- case 'string':
242
- case 'varchar':
243
- return Type.getType(StringType);
244
- case 'interval':
245
- return Type.getType(IntervalType);
246
- case 'text':
247
- return Type.getType(TextType);
248
- case 'int':
249
- case 'number':
250
- return Type.getType(IntegerType);
251
- case 'bigint':
252
- return Type.getType(BigIntType);
253
- case 'smallint':
254
- return Type.getType(SmallIntType);
255
- case 'tinyint':
256
- return Type.getType(TinyIntType);
257
- case 'mediumint':
258
- return Type.getType(MediumIntType);
259
- case 'float':
260
- return Type.getType(FloatType);
261
- case 'double':
262
- return Type.getType(DoubleType);
263
- case 'integer':
264
- return Type.getType(IntegerType);
265
- case 'decimal':
266
- case 'numeric':
267
- return Type.getType(DecimalType);
268
- case 'boolean':
269
- return Type.getType(BooleanType);
270
- case 'blob':
271
- case 'buffer':
272
- return Type.getType(BlobType);
273
- case 'uint8array':
274
- return Type.getType(Uint8ArrayType);
275
- case 'uuid':
276
- return Type.getType(UuidType);
277
- case 'date':
278
- return Type.getType(DateType);
279
- case 'datetime':
280
- case 'timestamp':
281
- return Type.getType(DateTimeType);
282
- case 'time':
283
- return Type.getType(TimeType);
284
- case 'object':
285
- case 'json':
286
- return Type.getType(JsonType);
287
- case 'enum':
288
- return Type.getType(EnumType);
289
- default:
290
- return Type.getType(UnknownType);
291
- }
292
- }
293
- /** Whether the platform supports multiple cascade paths to the same table. */
294
- supportsMultipleCascadePaths() {
295
- return true;
296
- }
297
- /**
298
- * Returns true if the platform supports ON UPDATE foreign key rules.
299
- * Oracle doesn't support ON UPDATE rules.
300
- */
301
- supportsOnUpdate() {
302
- return true;
303
- }
304
- /** Whether the connection supports executing multiple SQL statements in a single call. */
305
- supportsMultipleStatements() {
306
- return this.config.get('multipleStatements');
307
- }
308
- /** Whether the platform supports the UNION WHERE optimization for multi-branch queries. */
309
- supportsUnionWhere() {
310
- return false;
311
- }
312
- /** Returns the SQL type declaration used for array storage. */
313
- getArrayDeclarationSQL() {
314
- return 'text';
315
- }
316
- /** Serializes a string array into its database storage format. */
317
- marshallArray(values) {
318
- return values.join(',');
319
- }
320
- /** Deserializes a database-stored array string back into a string array. */
321
- unmarshallArray(value) {
322
- if (value === '') {
323
- return [];
324
- }
325
- return value.split(',');
326
- }
327
- getBlobDeclarationSQL() {
328
- return 'blob';
329
- }
330
- getJsonDeclarationSQL() {
331
- return 'json';
332
- }
333
- getSearchJsonPropertySQL(path, type, aliased) {
334
- return path;
335
- }
336
- getSearchJsonPropertyKey(path, type, aliased, value) {
337
- return path.join('.');
338
- }
339
- processJsonCondition(o, value, path, alias) {
340
- if (Utils.isPlainObject(value) && !Object.keys(value).some(k => Utils.isOperator(k))) {
341
- Utils.keys(value).forEach(k => {
342
- this.processJsonCondition(o, value[k], [...path, k], alias);
343
- });
344
- return o;
345
- }
346
- if (path.length === 1) {
347
- o[path[0]] = value;
348
- return o;
349
- }
350
- const type = this.getJsonValueType(value);
351
- const k = this.getSearchJsonPropertyKey(path, type, alias, value);
352
- o[k] = value;
353
- return o;
354
- }
355
- getJsonValueType(value) {
356
- if (Array.isArray(value)) {
357
- return typeof value[0];
358
- }
359
- if (Utils.isPlainObject(value) && Object.keys(value).every(k => Utils.isOperator(k))) {
360
- return this.getJsonValueType(Object.values(value)[0]);
361
- }
362
- return typeof value;
363
- }
364
- /* v8 ignore next */
365
- getJsonIndexDefinition(index) {
366
- return index.columnNames;
367
- }
368
- getFullTextWhereClause(prop) {
369
- throw new Error('Full text searching is not supported by this driver.');
370
- }
371
- supportsCreatingFullTextIndex() {
372
- return false;
373
- }
374
- getFullTextIndexExpression(indexName, schemaName, tableName, columns) {
375
- throw new Error('Full text searching is not supported by this driver.');
376
- }
377
- /** Whether the driver automatically parses JSON columns into JS objects. */
378
- convertsJsonAutomatically() {
379
- return true;
380
- }
381
- /** Converts a JS value to its JSON database representation (typically JSON.stringify). */
382
- convertJsonToDatabaseValue(value, context) {
383
- return JSON.stringify(value);
384
- }
385
- /** Converts a database JSON value to its JS representation. */
386
- convertJsonToJSValue(value, context) {
387
- return parseJsonSafe(value);
388
- }
389
- convertDateToJSValue(value) {
390
- return value;
391
- }
392
- convertIntervalToJSValue(value) {
393
- return value;
394
- }
395
- convertIntervalToDatabaseValue(value) {
396
- return value;
397
- }
398
- usesAsKeyword() {
399
- return true;
400
- }
401
- /**
402
- * Determines how UUID values are compared in the change set tracking.
403
- * Return `'string'` for inline string comparison (fast), or `'any'` for deep comparison via type methods.
404
- */
405
- compareUuids() {
406
- return 'string';
407
- }
408
- convertUuidToJSValue(value) {
409
- return value;
410
- }
411
- convertUuidToDatabaseValue(value) {
412
- return value;
413
- }
414
- /** Parses a string or numeric value into a Date object. */
415
- parseDate(value) {
416
- const date = new Date(value);
417
- /* v8 ignore next */
418
- if (isNaN(date.getTime())) {
419
- return value;
420
- }
421
- return date;
422
- }
423
- /** Returns the default EntityRepository class used by this platform. */
424
- getRepositoryClass() {
425
- return EntityRepository;
426
- }
427
- /** Returns the default character set for this platform. */
428
- getDefaultCharset() {
429
- return 'utf8';
430
- }
431
- /** Returns the exception converter for translating native errors to driver exceptions. */
432
- getExceptionConverter() {
433
- return this.exceptionConverter;
434
- }
435
- /**
436
- * Allows registering extensions of the driver automatically (e.g. `SchemaGenerator` extension in SQL drivers).
437
- */
438
- lookupExtensions(orm) {
439
- // no extensions by default
440
- }
441
- /** @internal */
442
- init(orm) {
443
- this.lookupExtensions(orm);
444
- }
445
- /** Retrieves a registered extension (e.g. SchemaGenerator, Migrator), throwing if not found. */
446
- getExtension(extensionName, extensionKey, moduleName, em) {
447
- const extension = this.config.getExtension(extensionKey);
448
- if (extension) {
449
- return extension;
450
- }
451
- /* v8 ignore next */
452
- throw new Error(`${extensionName} extension not registered. Provide it in the ORM config, or use the async \`MikroORM.init()\` method to load extensions automatically.`);
453
- }
454
- /* v8 ignore next: kept for type inference only */
455
- getSchemaGenerator(driver, em) {
456
- throw new Error(`${driver.constructor.name} does not support SchemaGenerator`);
457
- }
458
- /** Processes a date value before persisting, applying timezone or format conversions. */
459
- processDateProperty(value) {
460
- return value;
461
- }
462
- /** Wraps a table or column identifier with the platform-specific quote character. */
463
- quoteIdentifier(id, quote = '`') {
464
- const raw = Raw.getKnownFragment(id);
465
- if (raw) {
466
- return this.formatQuery(raw.sql, raw.params);
467
- }
468
- return `${quote}${id.toString().replace('.', `${quote}.${quote}`)}${quote}`;
469
- }
470
- /** Quotes a literal value for safe embedding in SQL. */
471
- quoteValue(value) {
472
- return value;
473
- }
38
+ exceptionConverter = new ExceptionConverter();
39
+ config;
40
+ namingStrategy;
41
+ timezone;
42
+ /** Whether this driver uses pivot tables for M:N relations (SQL drivers do, MongoDB does not). */
43
+ usesPivotTable() {
44
+ return false;
45
+ }
46
+ /** Whether this driver supports database transactions. */
47
+ supportsTransactions() {
48
+ return !this.config.get('disableTransactions');
49
+ }
50
+ /** Whether the driver wraps operations in implicit transactions by default. */
51
+ usesImplicitTransactions() {
52
+ return true;
53
+ }
54
+ /** Returns the default naming strategy constructor for this platform. */
55
+ getNamingStrategy() {
56
+ return UnderscoreNamingStrategy;
57
+ }
58
+ /** Whether the driver supports RETURNING clause (e.g. PostgreSQL). */
59
+ usesReturningStatement() {
60
+ return false;
61
+ }
62
+ /** Whether the driver supports OUTPUT clause (e.g. MSSQL). */
63
+ usesOutputStatement() {
64
+ return false;
65
+ }
66
+ /** Whether DELETE statements require explicit CASCADE keyword. */
67
+ usesCascadeStatement() {
68
+ return false;
69
+ }
70
+ /** for postgres native enums */
71
+ supportsNativeEnums() {
72
+ return false;
73
+ }
74
+ /** for postgres text enums (default) */
75
+ usesEnumCheckConstraints() {
76
+ return false;
77
+ }
78
+ /** Returns the check constraint expression for an enum array column, or null if unsupported. */
79
+ getEnumArrayCheckConstraintExpression(column, items) {
80
+ return null;
81
+ }
82
+ /** Whether this platform supports materialized views. */
83
+ supportsMaterializedViews() {
84
+ return false;
85
+ }
86
+ /** Returns the schema helper instance for this platform, or undefined if not supported. */
87
+ getSchemaHelper() {
88
+ return undefined;
89
+ }
90
+ /** Whether the platform automatically creates indexes on foreign key columns. */
91
+ indexForeignKeys() {
92
+ return false;
93
+ }
94
+ /**
95
+ * Whether or not the driver supports retuning list of created PKs back when multi-inserting
96
+ */
97
+ usesBatchInserts() {
98
+ return true;
99
+ }
100
+ /**
101
+ * Whether or not the driver supports updating many records at once
102
+ */
103
+ usesBatchUpdates() {
104
+ return true;
105
+ }
106
+ /** Whether the platform supports the DEFAULT keyword in INSERT statements. */
107
+ usesDefaultKeyword() {
108
+ return true;
109
+ }
110
+ /**
111
+ * Normalizes primary key wrapper to scalar value (e.g. mongodb's ObjectId to string)
112
+ */
113
+ normalizePrimaryKey(data) {
114
+ return data;
115
+ }
116
+ /**
117
+ * Converts scalar primary key representation to native driver wrapper (e.g. string to mongodb's ObjectId)
118
+ */
119
+ denormalizePrimaryKey(data) {
120
+ return data;
121
+ }
122
+ /**
123
+ * Returns the SQL specific for the platform to get the current timestamp
124
+ */
125
+ getCurrentTimestampSQL(length) {
126
+ return 'current_timestamp' + (length ? `(${length})` : '');
127
+ }
128
+ /** Returns the SQL type declaration for datetime columns. */
129
+ getDateTimeTypeDeclarationSQL(column) {
130
+ return 'datetime' + (column.length ? `(${column.length})` : '');
131
+ }
132
+ /** Returns the default fractional seconds precision for datetime columns. */
133
+ getDefaultDateTimeLength() {
134
+ return 0;
135
+ }
136
+ /** Returns the default length for varchar columns. */
137
+ getDefaultVarcharLength() {
138
+ return 255;
139
+ }
140
+ /** Returns the default length for char columns. */
141
+ getDefaultCharLength() {
142
+ return 1;
143
+ }
144
+ /** Returns the SQL type declaration for date columns. */
145
+ getDateTypeDeclarationSQL(length) {
146
+ return 'date' + (length ? `(${length})` : '');
147
+ }
148
+ /** Returns the SQL type declaration for time columns. */
149
+ getTimeTypeDeclarationSQL(length) {
150
+ return 'time' + (length ? `(${length})` : '');
151
+ }
152
+ /** Returns the SQL operator used for regular expression matching. */
153
+ getRegExpOperator(val, flags) {
154
+ return 'regexp';
155
+ }
156
+ /** Builds the SQL clause and parameters for a regular expression condition. */
157
+ mapRegExpCondition(mappedKey, value) {
158
+ const operator = this.getRegExpOperator(value.$re, value.$flags);
159
+ const quotedKey = this.quoteIdentifier(mappedKey);
160
+ return { sql: `${quotedKey} ${operator} ?`, params: [value.$re] };
161
+ }
162
+ /** Converts a JavaScript RegExp into a platform-specific regex representation. */
163
+ getRegExpValue(val) {
164
+ if (val.flags.includes('i')) {
165
+ return { $re: `(?i)${val.source}` };
166
+ }
167
+ return { $re: val.source };
168
+ }
169
+ /** Whether the given operator is allowed at the top level of a query condition. */
170
+ isAllowedTopLevelOperator(operator) {
171
+ return operator === '$not';
172
+ }
173
+ /** Converts a version field value for comparison in optimistic locking queries. */
174
+ convertVersionValue(value, prop) {
175
+ return value;
176
+ }
177
+ /** Returns the default fractional seconds precision for version timestamp columns. */
178
+ getDefaultVersionLength() {
179
+ return 3;
180
+ }
181
+ /** Whether the platform supports tuple comparison in WHERE clauses. */
182
+ allowsComparingTuples() {
183
+ return true;
184
+ }
185
+ /** Whether the given property maps to a bigint database column. */
186
+ isBigIntProperty(prop) {
187
+ return prop.columnTypes?.[0] === 'bigint';
188
+ }
189
+ /** Returns the default schema name for this platform (e.g. "public" for PostgreSQL). */
190
+ getDefaultSchemaName() {
191
+ return undefined;
192
+ }
193
+ /** Returns the SQL type declaration for boolean columns. */
194
+ getBooleanTypeDeclarationSQL() {
195
+ return 'boolean';
196
+ }
197
+ /** Returns the SQL type declaration for integer columns. */
198
+ getIntegerTypeDeclarationSQL(column) {
199
+ return 'int';
200
+ }
201
+ getSmallIntTypeDeclarationSQL(column) {
202
+ return 'smallint';
203
+ }
204
+ getMediumIntTypeDeclarationSQL(column) {
205
+ return 'mediumint';
206
+ }
207
+ getTinyIntTypeDeclarationSQL(column) {
208
+ return 'tinyint';
209
+ }
210
+ getBigIntTypeDeclarationSQL(column) {
211
+ return 'bigint';
212
+ }
213
+ getCharTypeDeclarationSQL(column) {
214
+ return `char(${column.length ?? this.getDefaultCharLength()})`;
215
+ }
216
+ getVarcharTypeDeclarationSQL(column) {
217
+ return `varchar(${column.length ?? this.getDefaultVarcharLength()})`;
218
+ }
219
+ getIntervalTypeDeclarationSQL(column) {
220
+ return 'interval' + (column.length ? `(${column.length})` : '');
221
+ }
222
+ getTextTypeDeclarationSQL(_column) {
223
+ return 'text';
224
+ }
225
+ getEnumTypeDeclarationSQL(column) {
226
+ if (column.items?.every(item => typeof item === 'string')) {
227
+ return `enum('${column.items.join("','")}')`;
228
+ }
229
+ return this.getTinyIntTypeDeclarationSQL(column);
230
+ }
231
+ getFloatDeclarationSQL() {
232
+ return 'float';
233
+ }
234
+ getDoubleDeclarationSQL() {
235
+ return 'double';
236
+ }
237
+ getDecimalTypeDeclarationSQL(column) {
238
+ const precision = column.precision ?? 10;
239
+ const scale = column.scale ?? 0;
240
+ return `numeric(${precision},${scale})`;
241
+ }
242
+ getUuidTypeDeclarationSQL(column) {
243
+ column.length ??= 36;
244
+ return this.getVarcharTypeDeclarationSQL(column);
245
+ }
246
+ /** Extracts the base type name from a full SQL type declaration (e.g. "varchar(255)" -> "varchar"). */
247
+ extractSimpleType(type) {
248
+ return /[^(), ]+/.exec(type.toLowerCase())[0];
249
+ }
250
+ /**
251
+ * This should be used only to compare types, it can strip some information like the length.
252
+ */
253
+ normalizeColumnType(type, options) {
254
+ return type.toLowerCase();
255
+ }
256
+ /** Returns the mapped Type instance for a given SQL/runtime type string. */
257
+ getMappedType(type) {
258
+ const mappedType = this.config.get('discovery').getMappedType?.(type, this);
259
+ return mappedType ?? this.getDefaultMappedType(type);
260
+ }
261
+ /** Returns the default mapped Type for a given type string when no custom mapping is configured. */
262
+ getDefaultMappedType(type) {
263
+ if (type.endsWith('[]')) {
264
+ return Type.getType(ArrayType);
265
+ }
266
+ switch (this.extractSimpleType(type)) {
267
+ case 'character':
268
+ case 'char':
269
+ return Type.getType(CharacterType);
270
+ case 'string':
271
+ case 'varchar':
272
+ return Type.getType(StringType);
273
+ case 'interval':
274
+ return Type.getType(IntervalType);
275
+ case 'text':
276
+ return Type.getType(TextType);
277
+ case 'int':
278
+ case 'number':
279
+ return Type.getType(IntegerType);
280
+ case 'bigint':
281
+ return Type.getType(BigIntType);
282
+ case 'smallint':
283
+ return Type.getType(SmallIntType);
284
+ case 'tinyint':
285
+ return Type.getType(TinyIntType);
286
+ case 'mediumint':
287
+ return Type.getType(MediumIntType);
288
+ case 'float':
289
+ return Type.getType(FloatType);
290
+ case 'double':
291
+ return Type.getType(DoubleType);
292
+ case 'integer':
293
+ return Type.getType(IntegerType);
294
+ case 'decimal':
295
+ case 'numeric':
296
+ return Type.getType(DecimalType);
297
+ case 'boolean':
298
+ return Type.getType(BooleanType);
299
+ case 'blob':
300
+ case 'buffer':
301
+ return Type.getType(BlobType);
302
+ case 'uint8array':
303
+ return Type.getType(Uint8ArrayType);
304
+ case 'uuid':
305
+ return Type.getType(UuidType);
306
+ case 'date':
307
+ return Type.getType(DateType);
308
+ case 'datetime':
309
+ case 'timestamp':
310
+ return Type.getType(DateTimeType);
311
+ case 'time':
312
+ return Type.getType(TimeType);
313
+ case 'object':
314
+ case 'json':
315
+ return Type.getType(JsonType);
316
+ case 'enum':
317
+ return Type.getType(EnumType);
318
+ default:
319
+ return Type.getType(UnknownType);
320
+ }
321
+ }
322
+ /** Whether the platform supports multiple cascade paths to the same table. */
323
+ supportsMultipleCascadePaths() {
324
+ return true;
325
+ }
326
+ /**
327
+ * Returns true if the platform supports ON UPDATE foreign key rules.
328
+ * Oracle doesn't support ON UPDATE rules.
329
+ */
330
+ supportsOnUpdate() {
331
+ return true;
332
+ }
333
+ /** Whether the connection supports executing multiple SQL statements in a single call. */
334
+ supportsMultipleStatements() {
335
+ return this.config.get('multipleStatements');
336
+ }
337
+ /** Whether the platform supports the UNION WHERE optimization for multi-branch queries. */
338
+ supportsUnionWhere() {
339
+ return false;
340
+ }
341
+ /** Returns the SQL type declaration used for array storage. */
342
+ getArrayDeclarationSQL() {
343
+ return 'text';
344
+ }
345
+ /** Serializes a string array into its database storage format. */
346
+ marshallArray(values) {
347
+ return values.join(',');
348
+ }
349
+ /** Deserializes a database-stored array string back into a string array. */
350
+ unmarshallArray(value) {
351
+ if (value === '') {
352
+ return [];
353
+ }
354
+ return value.split(',');
355
+ }
356
+ getBlobDeclarationSQL() {
357
+ return 'blob';
358
+ }
359
+ getJsonDeclarationSQL() {
360
+ return 'json';
361
+ }
362
+ getSearchJsonPropertySQL(path, type, aliased) {
363
+ return path;
364
+ }
365
+ getSearchJsonPropertyKey(path, type, aliased, value) {
366
+ return path.join('.');
367
+ }
368
+ processJsonCondition(o, value, path, alias) {
369
+ if (Utils.isPlainObject(value) && !Object.keys(value).some(k => Utils.isOperator(k))) {
370
+ Utils.keys(value).forEach(k => {
371
+ this.processJsonCondition(o, value[k], [...path, k], alias);
372
+ });
373
+ return o;
374
+ }
375
+ if (path.length === 1) {
376
+ o[path[0]] = value;
377
+ return o;
378
+ }
379
+ const type = this.getJsonValueType(value);
380
+ const k = this.getSearchJsonPropertyKey(path, type, alias, value);
381
+ o[k] = value;
382
+ return o;
383
+ }
384
+ getJsonValueType(value) {
385
+ if (Array.isArray(value)) {
386
+ return typeof value[0];
387
+ }
388
+ if (Utils.isPlainObject(value) && Object.keys(value).every(k => Utils.isOperator(k))) {
389
+ return this.getJsonValueType(Object.values(value)[0]);
390
+ }
391
+ return typeof value;
392
+ }
393
+ /* v8 ignore next */
394
+ getJsonIndexDefinition(index) {
395
+ return index.columnNames;
396
+ }
397
+ getFullTextWhereClause(prop) {
398
+ throw new Error('Full text searching is not supported by this driver.');
399
+ }
400
+ supportsCreatingFullTextIndex() {
401
+ return false;
402
+ }
403
+ getFullTextIndexExpression(indexName, schemaName, tableName, columns) {
404
+ throw new Error('Full text searching is not supported by this driver.');
405
+ }
406
+ /** Whether the driver automatically parses JSON columns into JS objects. */
407
+ convertsJsonAutomatically() {
408
+ return true;
409
+ }
410
+ /** Converts a JS value to its JSON database representation (typically JSON.stringify). */
411
+ convertJsonToDatabaseValue(value, context) {
412
+ return JSON.stringify(value);
413
+ }
414
+ /** Converts a database JSON value to its JS representation. */
415
+ convertJsonToJSValue(value, context) {
416
+ return parseJsonSafe(value);
417
+ }
418
+ convertDateToJSValue(value) {
419
+ return value;
420
+ }
421
+ convertIntervalToJSValue(value) {
422
+ return value;
423
+ }
424
+ convertIntervalToDatabaseValue(value) {
425
+ return value;
426
+ }
427
+ usesAsKeyword() {
428
+ return true;
429
+ }
430
+ /**
431
+ * Determines how UUID values are compared in the change set tracking.
432
+ * Return `'string'` for inline string comparison (fast), or `'any'` for deep comparison via type methods.
433
+ */
434
+ compareUuids() {
435
+ return 'string';
436
+ }
437
+ convertUuidToJSValue(value) {
438
+ return value;
439
+ }
440
+ convertUuidToDatabaseValue(value) {
441
+ return value;
442
+ }
443
+ /** Parses a string or numeric value into a Date object. */
444
+ parseDate(value) {
445
+ const date = new Date(value);
474
446
  /* v8 ignore next */
475
- escape(value) {
476
- return value;
477
- }
478
- /** Replaces `?` placeholders in SQL with quoted parameter values. */
479
- formatQuery(sql, params) {
480
- if (params.length === 0) {
481
- return sql;
482
- }
483
- // fast string replace without regexps
484
- let j = 0;
485
- let pos = 0;
486
- let ret = '';
487
- if (sql.startsWith('?')) {
488
- if (sql[1] === '?') {
489
- ret += this.quoteIdentifier(params[j++]);
490
- pos = 2;
491
- }
492
- else {
493
- ret += this.quoteValue(params[j++]);
494
- pos = 1;
495
- }
496
- }
497
- while (pos < sql.length) {
498
- const idx = sql.indexOf('?', pos + 1);
499
- if (idx === -1) {
500
- ret += sql.substring(pos, sql.length);
501
- break;
502
- }
503
- if (sql.substring(idx - 1, idx + 1) === '\\?') {
504
- ret += sql.substring(pos, idx - 1) + '?';
505
- pos = idx + 1;
506
- }
507
- else if (sql.substring(idx, idx + 2) === '??') {
508
- ret += sql.substring(pos, idx) + this.quoteIdentifier(params[j++]);
509
- pos = idx + 2;
510
- }
511
- else {
512
- ret += sql.substring(pos, idx) + this.quoteValue(params[j++]);
513
- pos = idx + 1;
514
- }
515
- }
516
- return ret;
517
- }
518
- /** Deep-clones embeddable data and tags it for JSON serialization. */
519
- cloneEmbeddable(data) {
520
- const copy = clone(data);
521
- // tag the copy so we know it should be stringified when quoting (so we know how to treat JSON arrays)
522
- Object.defineProperty(copy, JsonProperty, { enumerable: false, value: true });
523
- return copy;
524
- }
525
- /** Initializes the platform with the ORM configuration. */
526
- setConfig(config) {
527
- this.config = config;
528
- this.namingStrategy = config.getNamingStrategy();
529
- if (this.config.get('forceUtcTimezone')) {
530
- this.timezone = 'Z';
531
- }
532
- else {
533
- this.timezone = this.config.get('timezone');
534
- }
535
- }
536
- /** Returns the current ORM configuration. */
537
- getConfig() {
538
- return this.config;
539
- }
540
- /** Returns the configured timezone, or undefined if not set. */
541
- getTimezone() {
542
- return this.timezone;
543
- }
544
- /** Whether the given property represents a numeric database column. */
545
- isNumericProperty(prop, ignoreCustomType = false) {
546
- const numericMappedType = prop.columnTypes?.[0] && this.isNumericColumn(this.getMappedType(prop.columnTypes[0]));
547
- return numericMappedType || prop.type === 'number' || this.isBigIntProperty(prop);
548
- }
549
- /** Whether the given mapped type represents a numeric column. */
550
- isNumericColumn(mappedType) {
551
- return [IntegerType, SmallIntType, BigIntType, TinyIntType].some(t => mappedType instanceof t);
552
- }
553
- /** Whether the platform supports unsigned integer columns. */
554
- supportsUnsigned() {
555
- return false;
447
+ if (isNaN(date.getTime())) {
448
+ return value;
449
+ }
450
+ return date;
451
+ }
452
+ /** Returns the default EntityRepository class used by this platform. */
453
+ getRepositoryClass() {
454
+ return EntityRepository;
455
+ }
456
+ /** Returns the default character set for this platform. */
457
+ getDefaultCharset() {
458
+ return 'utf8';
459
+ }
460
+ /** Returns the exception converter for translating native errors to driver exceptions. */
461
+ getExceptionConverter() {
462
+ return this.exceptionConverter;
463
+ }
464
+ /**
465
+ * Allows registering extensions of the driver automatically (e.g. `SchemaGenerator` extension in SQL drivers).
466
+ */
467
+ lookupExtensions(orm) {
468
+ // no extensions by default
469
+ }
470
+ /** @internal */
471
+ init(orm) {
472
+ this.lookupExtensions(orm);
473
+ }
474
+ /** Retrieves a registered extension (e.g. SchemaGenerator, Migrator), throwing if not found. */
475
+ getExtension(extensionName, extensionKey, moduleName, em) {
476
+ const extension = this.config.getExtension(extensionKey);
477
+ if (extension) {
478
+ return extension;
556
479
  }
557
- /**
558
- * Returns the default name of index for the given columns
559
- */
560
- getIndexName(tableName, columns, type) {
561
- return this.namingStrategy.indexName(tableName, columns, type);
562
- }
563
- /** Returns the default primary key constraint name. */
564
- getDefaultPrimaryName(tableName, columns) {
565
- return 'primary';
566
- }
567
- /** Whether the platform supports custom names for primary key constraints. */
568
- supportsCustomPrimaryKeyNames() {
569
- return false;
570
- }
571
- /** Whether the given property key is included in the populate hint. */
572
- isPopulated(key, populate) {
573
- return populate === true || (populate !== false && populate.some(p => p.field === key || p.all));
574
- }
575
- /** Whether the given property should be included as a column in the SELECT query. */
576
- shouldHaveColumn(prop, populate, exclude, includeFormulas = true, ignoreInlineEmbeddables = true) {
577
- if (exclude?.includes(prop.name)) {
578
- return false;
579
- }
580
- if (exclude?.find(k => k.startsWith(`${prop.name}.`) && !this.isPopulated(prop.name, populate))) {
581
- return false;
582
- }
583
- if (prop.formula) {
584
- return includeFormulas && (!prop.lazy || this.isPopulated(prop.name, populate));
585
- }
586
- if (prop.persist === false) {
587
- return false;
588
- }
589
- if (prop.lazy && (populate === false || (populate !== true && !populate.some(p => p.field === prop.name)))) {
590
- return false;
591
- }
592
- if ([ReferenceKind.SCALAR, ReferenceKind.MANY_TO_ONE].includes(prop.kind)) {
593
- return true;
594
- }
595
- if (prop.kind === ReferenceKind.EMBEDDED) {
596
- return prop.object || ignoreInlineEmbeddables;
597
- }
598
- return prop.kind === ReferenceKind.ONE_TO_ONE && prop.owner;
599
- }
600
- /**
601
- * Currently not supported due to how knex does complex sqlite diffing (always based on current schema)
602
- */
603
- /** Whether the platform supports generating down migrations. */
604
- supportsDownMigrations() {
605
- return true;
606
- }
607
- /** Whether the platform supports deferred unique constraints. */
608
- supportsDeferredUniqueConstraints() {
609
- return true;
610
- }
611
- /** Platform-specific validation of entity metadata. */
612
- validateMetadata(meta) {
613
- return;
614
- }
615
- /**
616
- * Generates a custom order by statement given a set of in order values, eg.
617
- * ORDER BY (CASE WHEN priority = 'low' THEN 1 WHEN priority = 'medium' THEN 2 ELSE NULL END)
618
- */
619
- generateCustomOrder(escapedColumn, values) {
620
- throw new Error('Not supported');
621
- }
622
- /**
623
- * Returns default client url for given driver (e.g. mongodb://127.0.0.1:27017 for mongodb)
624
- */
625
- getDefaultClientUrl() {
626
- return '';
627
- }
628
- /**
629
- * @internal
630
- */
631
- castColumn(prop) {
632
- return '';
633
- }
634
- /**
635
- * @internal
636
- */
637
- castJsonValue(prop) {
638
- return '';
639
- }
640
- /**
641
- * @internal
642
- */
643
- clone() {
644
- return this;
645
- }
646
- /** @ignore */
647
480
  /* v8 ignore next */
648
- [Symbol.for('nodejs.util.inspect.custom')]() {
649
- return `[${this.constructor.name}]`;
650
- }
481
+ throw new Error(
482
+ `${extensionName} extension not registered. Provide it in the ORM config, or use the async \`MikroORM.init()\` method to load extensions automatically.`,
483
+ );
484
+ }
485
+ /* v8 ignore next: kept for type inference only */
486
+ getSchemaGenerator(driver, em) {
487
+ throw new Error(`${driver.constructor.name} does not support SchemaGenerator`);
488
+ }
489
+ /** Processes a date value before persisting, applying timezone or format conversions. */
490
+ processDateProperty(value) {
491
+ return value;
492
+ }
493
+ /** Wraps a table or column identifier with the platform-specific quote character. */
494
+ quoteIdentifier(id, quote = '`') {
495
+ const raw = Raw.getKnownFragment(id);
496
+ if (raw) {
497
+ return this.formatQuery(raw.sql, raw.params);
498
+ }
499
+ return `${quote}${id.toString().replace('.', `${quote}.${quote}`)}${quote}`;
500
+ }
501
+ /** Quotes a literal value for safe embedding in SQL. */
502
+ quoteValue(value) {
503
+ return value;
504
+ }
505
+ /* v8 ignore next */
506
+ escape(value) {
507
+ return value;
508
+ }
509
+ /** Replaces `?` placeholders in SQL with quoted parameter values. */
510
+ formatQuery(sql, params) {
511
+ if (params.length === 0) {
512
+ return sql;
513
+ }
514
+ // fast string replace without regexps
515
+ let j = 0;
516
+ let pos = 0;
517
+ let ret = '';
518
+ if (sql.startsWith('?')) {
519
+ if (sql[1] === '?') {
520
+ ret += this.quoteIdentifier(params[j++]);
521
+ pos = 2;
522
+ } else {
523
+ ret += this.quoteValue(params[j++]);
524
+ pos = 1;
525
+ }
526
+ }
527
+ while (pos < sql.length) {
528
+ const idx = sql.indexOf('?', pos + 1);
529
+ if (idx === -1) {
530
+ ret += sql.substring(pos, sql.length);
531
+ break;
532
+ }
533
+ if (sql.substring(idx - 1, idx + 1) === '\\?') {
534
+ ret += sql.substring(pos, idx - 1) + '?';
535
+ pos = idx + 1;
536
+ } else if (sql.substring(idx, idx + 2) === '??') {
537
+ ret += sql.substring(pos, idx) + this.quoteIdentifier(params[j++]);
538
+ pos = idx + 2;
539
+ } else {
540
+ ret += sql.substring(pos, idx) + this.quoteValue(params[j++]);
541
+ pos = idx + 1;
542
+ }
543
+ }
544
+ return ret;
545
+ }
546
+ /** Deep-clones embeddable data and tags it for JSON serialization. */
547
+ cloneEmbeddable(data) {
548
+ const copy = clone(data);
549
+ // tag the copy so we know it should be stringified when quoting (so we know how to treat JSON arrays)
550
+ Object.defineProperty(copy, JsonProperty, { enumerable: false, value: true });
551
+ return copy;
552
+ }
553
+ /** Initializes the platform with the ORM configuration. */
554
+ setConfig(config) {
555
+ this.config = config;
556
+ this.namingStrategy = config.getNamingStrategy();
557
+ if (this.config.get('forceUtcTimezone')) {
558
+ this.timezone = 'Z';
559
+ } else {
560
+ this.timezone = this.config.get('timezone');
561
+ }
562
+ }
563
+ /** Returns the current ORM configuration. */
564
+ getConfig() {
565
+ return this.config;
566
+ }
567
+ /** Returns the configured timezone, or undefined if not set. */
568
+ getTimezone() {
569
+ return this.timezone;
570
+ }
571
+ /** Whether the given property represents a numeric database column. */
572
+ isNumericProperty(prop, ignoreCustomType = false) {
573
+ const numericMappedType = prop.columnTypes?.[0] && this.isNumericColumn(this.getMappedType(prop.columnTypes[0]));
574
+ return numericMappedType || prop.type === 'number' || this.isBigIntProperty(prop);
575
+ }
576
+ /** Whether the given mapped type represents a numeric column. */
577
+ isNumericColumn(mappedType) {
578
+ return [IntegerType, SmallIntType, BigIntType, TinyIntType].some(t => mappedType instanceof t);
579
+ }
580
+ /** Whether the platform supports unsigned integer columns. */
581
+ supportsUnsigned() {
582
+ return false;
583
+ }
584
+ /**
585
+ * Returns the default name of index for the given columns
586
+ */
587
+ getIndexName(tableName, columns, type) {
588
+ return this.namingStrategy.indexName(tableName, columns, type);
589
+ }
590
+ /** Returns the default primary key constraint name. */
591
+ getDefaultPrimaryName(tableName, columns) {
592
+ return 'primary';
593
+ }
594
+ /** Whether the platform supports custom names for primary key constraints. */
595
+ supportsCustomPrimaryKeyNames() {
596
+ return false;
597
+ }
598
+ /** Whether the given property key is included in the populate hint. */
599
+ isPopulated(key, populate) {
600
+ return populate === true || (populate !== false && populate.some(p => p.field === key || p.all));
601
+ }
602
+ /** Whether the given property should be included as a column in the SELECT query. */
603
+ shouldHaveColumn(prop, populate, exclude, includeFormulas = true, ignoreInlineEmbeddables = true) {
604
+ if (exclude?.includes(prop.name)) {
605
+ return false;
606
+ }
607
+ if (exclude?.find(k => k.startsWith(`${prop.name}.`) && !this.isPopulated(prop.name, populate))) {
608
+ return false;
609
+ }
610
+ if (prop.formula) {
611
+ return includeFormulas && (!prop.lazy || this.isPopulated(prop.name, populate));
612
+ }
613
+ if (prop.persist === false) {
614
+ return false;
615
+ }
616
+ if (prop.lazy && (populate === false || (populate !== true && !populate.some(p => p.field === prop.name)))) {
617
+ return false;
618
+ }
619
+ if ([ReferenceKind.SCALAR, ReferenceKind.MANY_TO_ONE].includes(prop.kind)) {
620
+ return true;
621
+ }
622
+ if (prop.kind === ReferenceKind.EMBEDDED) {
623
+ return prop.object || ignoreInlineEmbeddables;
624
+ }
625
+ return prop.kind === ReferenceKind.ONE_TO_ONE && prop.owner;
626
+ }
627
+ /**
628
+ * Currently not supported due to how knex does complex sqlite diffing (always based on current schema)
629
+ */
630
+ /** Whether the platform supports generating down migrations. */
631
+ supportsDownMigrations() {
632
+ return true;
633
+ }
634
+ /** Whether the platform supports deferred unique constraints. */
635
+ supportsDeferredUniqueConstraints() {
636
+ return true;
637
+ }
638
+ /** Platform-specific validation of entity metadata. */
639
+ validateMetadata(meta) {
640
+ return;
641
+ }
642
+ /**
643
+ * Generates a custom order by statement given a set of in order values, eg.
644
+ * ORDER BY (CASE WHEN priority = 'low' THEN 1 WHEN priority = 'medium' THEN 2 ELSE NULL END)
645
+ */
646
+ generateCustomOrder(escapedColumn, values) {
647
+ throw new Error('Not supported');
648
+ }
649
+ /**
650
+ * Returns default client url for given driver (e.g. mongodb://127.0.0.1:27017 for mongodb)
651
+ */
652
+ getDefaultClientUrl() {
653
+ return '';
654
+ }
655
+ /**
656
+ * @internal
657
+ */
658
+ castColumn(prop) {
659
+ return '';
660
+ }
661
+ /**
662
+ * @internal
663
+ */
664
+ castJsonValue(prop) {
665
+ return '';
666
+ }
667
+ /**
668
+ * @internal
669
+ */
670
+ clone() {
671
+ return this;
672
+ }
673
+ /** @ignore */
674
+ /* v8 ignore next */
675
+ [Symbol.for('nodejs.util.inspect.custom')]() {
676
+ return `[${this.constructor.name}]`;
677
+ }
651
678
  }