@mikro-orm/core 7.0.15 → 7.0.16-dev.0

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