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

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