@mikro-orm/core 7.0.0-dev.33 → 7.0.0-dev.331

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 (218) hide show
  1. package/EntityManager.d.ts +70 -75
  2. package/EntityManager.js +487 -402
  3. package/MikroORM.d.ts +45 -38
  4. package/MikroORM.js +123 -156
  5. package/README.md +7 -4
  6. package/cache/FileCacheAdapter.d.ts +2 -7
  7. package/cache/FileCacheAdapter.js +35 -30
  8. package/cache/GeneratedCacheAdapter.d.ts +1 -2
  9. package/cache/GeneratedCacheAdapter.js +6 -8
  10. package/cache/MemoryCacheAdapter.d.ts +1 -2
  11. package/cache/MemoryCacheAdapter.js +8 -8
  12. package/cache/index.d.ts +1 -2
  13. package/cache/index.js +0 -2
  14. package/connections/Connection.d.ts +12 -5
  15. package/connections/Connection.js +37 -15
  16. package/drivers/DatabaseDriver.d.ts +25 -18
  17. package/drivers/DatabaseDriver.js +144 -45
  18. package/drivers/IDatabaseDriver.d.ts +118 -23
  19. package/entity/BaseEntity.d.ts +63 -4
  20. package/entity/BaseEntity.js +0 -3
  21. package/entity/Collection.d.ts +95 -31
  22. package/entity/Collection.js +487 -139
  23. package/entity/EntityAssigner.js +37 -25
  24. package/entity/EntityFactory.d.ts +8 -9
  25. package/entity/EntityFactory.js +152 -100
  26. package/entity/EntityHelper.d.ts +2 -2
  27. package/entity/EntityHelper.js +69 -27
  28. package/entity/EntityLoader.d.ts +12 -13
  29. package/entity/EntityLoader.js +286 -125
  30. package/entity/EntityRepository.d.ts +28 -8
  31. package/entity/EntityRepository.js +8 -2
  32. package/entity/PolymorphicRef.d.ts +12 -0
  33. package/entity/PolymorphicRef.js +18 -0
  34. package/entity/Reference.d.ts +3 -8
  35. package/entity/Reference.js +62 -29
  36. package/entity/WrappedEntity.d.ts +7 -10
  37. package/entity/WrappedEntity.js +6 -7
  38. package/entity/defineEntity.d.ts +472 -313
  39. package/entity/defineEntity.js +134 -290
  40. package/entity/index.d.ts +2 -2
  41. package/entity/index.js +2 -2
  42. package/entity/utils.d.ts +6 -1
  43. package/entity/utils.js +46 -11
  44. package/entity/validators.d.ts +11 -0
  45. package/entity/validators.js +66 -0
  46. package/enums.d.ts +8 -6
  47. package/enums.js +13 -17
  48. package/errors.d.ts +26 -16
  49. package/errors.js +63 -31
  50. package/events/EventManager.d.ts +3 -5
  51. package/events/EventManager.js +37 -26
  52. package/events/index.d.ts +1 -1
  53. package/events/index.js +0 -1
  54. package/exceptions.js +9 -2
  55. package/hydration/Hydrator.js +1 -2
  56. package/hydration/ObjectHydrator.d.ts +5 -6
  57. package/hydration/ObjectHydrator.js +109 -50
  58. package/index.d.ts +2 -2
  59. package/index.js +1 -2
  60. package/logging/DefaultLogger.d.ts +1 -1
  61. package/logging/DefaultLogger.js +3 -4
  62. package/logging/SimpleLogger.d.ts +1 -1
  63. package/logging/colors.d.ts +1 -1
  64. package/logging/colors.js +4 -6
  65. package/logging/index.d.ts +2 -1
  66. package/logging/index.js +1 -1
  67. package/logging/inspect.d.ts +2 -0
  68. package/logging/inspect.js +11 -0
  69. package/metadata/EntitySchema.d.ts +47 -23
  70. package/metadata/EntitySchema.js +103 -34
  71. package/metadata/MetadataDiscovery.d.ts +65 -18
  72. package/metadata/MetadataDiscovery.js +940 -424
  73. package/metadata/MetadataProvider.d.ts +11 -2
  74. package/metadata/MetadataProvider.js +71 -2
  75. package/metadata/MetadataStorage.d.ts +11 -13
  76. package/metadata/MetadataStorage.js +79 -48
  77. package/metadata/MetadataValidator.d.ts +32 -9
  78. package/metadata/MetadataValidator.js +214 -44
  79. package/metadata/discover-entities.d.ts +5 -0
  80. package/metadata/discover-entities.js +40 -0
  81. package/metadata/index.d.ts +1 -1
  82. package/metadata/index.js +0 -1
  83. package/metadata/types.d.ts +577 -0
  84. package/metadata/types.js +1 -0
  85. package/naming-strategy/AbstractNamingStrategy.d.ts +16 -4
  86. package/naming-strategy/AbstractNamingStrategy.js +26 -5
  87. package/naming-strategy/EntityCaseNamingStrategy.d.ts +3 -3
  88. package/naming-strategy/EntityCaseNamingStrategy.js +7 -6
  89. package/naming-strategy/MongoNamingStrategy.d.ts +3 -3
  90. package/naming-strategy/MongoNamingStrategy.js +6 -6
  91. package/naming-strategy/NamingStrategy.d.ts +28 -4
  92. package/naming-strategy/UnderscoreNamingStrategy.d.ts +3 -3
  93. package/naming-strategy/UnderscoreNamingStrategy.js +6 -6
  94. package/naming-strategy/index.d.ts +1 -1
  95. package/naming-strategy/index.js +0 -1
  96. package/not-supported.d.ts +2 -0
  97. package/not-supported.js +8 -0
  98. package/package.json +47 -36
  99. package/platforms/ExceptionConverter.js +1 -1
  100. package/platforms/Platform.d.ts +33 -15
  101. package/platforms/Platform.js +125 -69
  102. package/serialization/EntitySerializer.d.ts +6 -3
  103. package/serialization/EntitySerializer.js +54 -30
  104. package/serialization/EntityTransformer.js +37 -22
  105. package/serialization/SerializationContext.d.ts +10 -14
  106. package/serialization/SerializationContext.js +24 -19
  107. package/types/ArrayType.d.ts +1 -1
  108. package/types/ArrayType.js +2 -3
  109. package/types/BigIntType.js +1 -1
  110. package/types/BlobType.d.ts +0 -1
  111. package/types/BlobType.js +0 -3
  112. package/types/BooleanType.d.ts +1 -0
  113. package/types/BooleanType.js +3 -0
  114. package/types/DecimalType.js +2 -2
  115. package/types/DoubleType.js +1 -1
  116. package/types/EnumArrayType.js +1 -2
  117. package/types/JsonType.d.ts +1 -1
  118. package/types/JsonType.js +7 -2
  119. package/types/TinyIntType.js +1 -1
  120. package/types/Type.d.ts +2 -4
  121. package/types/Type.js +3 -3
  122. package/types/Uint8ArrayType.d.ts +0 -1
  123. package/types/Uint8ArrayType.js +1 -4
  124. package/types/UuidType.d.ts +2 -0
  125. package/types/UuidType.js +14 -2
  126. package/types/index.d.ts +3 -2
  127. package/typings.d.ts +427 -170
  128. package/typings.js +100 -45
  129. package/unit-of-work/ChangeSet.d.ts +4 -6
  130. package/unit-of-work/ChangeSet.js +8 -9
  131. package/unit-of-work/ChangeSetComputer.d.ts +2 -12
  132. package/unit-of-work/ChangeSetComputer.js +61 -38
  133. package/unit-of-work/ChangeSetPersister.d.ts +10 -17
  134. package/unit-of-work/ChangeSetPersister.js +136 -73
  135. package/unit-of-work/CommitOrderCalculator.d.ts +13 -14
  136. package/unit-of-work/CommitOrderCalculator.js +22 -20
  137. package/unit-of-work/IdentityMap.d.ts +12 -3
  138. package/unit-of-work/IdentityMap.js +51 -13
  139. package/unit-of-work/UnitOfWork.d.ts +39 -23
  140. package/unit-of-work/UnitOfWork.js +441 -246
  141. package/utils/AbstractMigrator.d.ts +101 -0
  142. package/utils/AbstractMigrator.js +303 -0
  143. package/utils/AbstractSchemaGenerator.d.ts +5 -5
  144. package/utils/AbstractSchemaGenerator.js +30 -18
  145. package/utils/AsyncContext.d.ts +6 -0
  146. package/utils/AsyncContext.js +42 -0
  147. package/utils/Configuration.d.ts +647 -185
  148. package/utils/Configuration.js +215 -252
  149. package/utils/ConfigurationLoader.d.ts +1 -52
  150. package/utils/ConfigurationLoader.js +1 -330
  151. package/utils/Cursor.d.ts +3 -6
  152. package/utils/Cursor.js +32 -17
  153. package/utils/DataloaderUtils.d.ts +10 -5
  154. package/utils/DataloaderUtils.js +42 -22
  155. package/utils/EntityComparator.d.ts +21 -21
  156. package/utils/EntityComparator.js +224 -118
  157. package/utils/QueryHelper.d.ts +34 -7
  158. package/utils/QueryHelper.js +183 -72
  159. package/utils/RawQueryFragment.d.ts +28 -34
  160. package/utils/RawQueryFragment.js +37 -72
  161. package/utils/RequestContext.js +2 -2
  162. package/utils/TransactionContext.js +2 -2
  163. package/utils/TransactionManager.js +11 -8
  164. package/utils/Utils.d.ts +16 -127
  165. package/utils/Utils.js +104 -402
  166. package/utils/clone.js +13 -23
  167. package/utils/env-vars.d.ts +7 -0
  168. package/utils/env-vars.js +98 -0
  169. package/utils/fs-utils.d.ts +20 -0
  170. package/utils/fs-utils.js +193 -0
  171. package/utils/index.d.ts +1 -3
  172. package/utils/index.js +1 -3
  173. package/utils/upsert-utils.d.ts +9 -4
  174. package/utils/upsert-utils.js +51 -5
  175. package/decorators/Check.d.ts +0 -3
  176. package/decorators/Check.js +0 -13
  177. package/decorators/CreateRequestContext.d.ts +0 -3
  178. package/decorators/CreateRequestContext.js +0 -32
  179. package/decorators/Embeddable.d.ts +0 -8
  180. package/decorators/Embeddable.js +0 -11
  181. package/decorators/Embedded.d.ts +0 -12
  182. package/decorators/Embedded.js +0 -18
  183. package/decorators/Entity.d.ts +0 -33
  184. package/decorators/Entity.js +0 -12
  185. package/decorators/Enum.d.ts +0 -9
  186. package/decorators/Enum.js +0 -16
  187. package/decorators/Filter.d.ts +0 -2
  188. package/decorators/Filter.js +0 -8
  189. package/decorators/Formula.d.ts +0 -4
  190. package/decorators/Formula.js +0 -15
  191. package/decorators/Indexed.d.ts +0 -19
  192. package/decorators/Indexed.js +0 -20
  193. package/decorators/ManyToMany.d.ts +0 -42
  194. package/decorators/ManyToMany.js +0 -14
  195. package/decorators/ManyToOne.d.ts +0 -34
  196. package/decorators/ManyToOne.js +0 -14
  197. package/decorators/OneToMany.d.ts +0 -28
  198. package/decorators/OneToMany.js +0 -17
  199. package/decorators/OneToOne.d.ts +0 -28
  200. package/decorators/OneToOne.js +0 -7
  201. package/decorators/PrimaryKey.d.ts +0 -8
  202. package/decorators/PrimaryKey.js +0 -20
  203. package/decorators/Property.d.ts +0 -250
  204. package/decorators/Property.js +0 -32
  205. package/decorators/Transactional.d.ts +0 -14
  206. package/decorators/Transactional.js +0 -28
  207. package/decorators/hooks.d.ts +0 -16
  208. package/decorators/hooks.js +0 -47
  209. package/decorators/index.d.ts +0 -17
  210. package/decorators/index.js +0 -17
  211. package/entity/ArrayCollection.d.ts +0 -118
  212. package/entity/ArrayCollection.js +0 -407
  213. package/entity/EntityValidator.d.ts +0 -19
  214. package/entity/EntityValidator.js +0 -150
  215. package/metadata/ReflectMetadataProvider.d.ts +0 -8
  216. package/metadata/ReflectMetadataProvider.js +0 -44
  217. package/utils/resolveContextProvider.d.ts +0 -10
  218. package/utils/resolveContextProvider.js +0 -28
@@ -1,18 +1,17 @@
1
- import { globSync } from 'tinyglobby';
2
1
  import { existsSync, readFileSync, writeFileSync, unlinkSync } from 'node:fs';
2
+ import { fs } from '../utils/fs-utils.js';
3
3
  import { Utils } from '../utils/Utils.js';
4
4
  export class FileCacheAdapter {
5
- options;
6
- baseDir;
7
- pretty;
8
- hashAlgorithm;
9
- VERSION = Utils.getORMVersion();
10
- cache = {};
11
- constructor(options, baseDir, pretty = false, hashAlgorithm = 'md5') {
12
- this.options = options;
13
- this.baseDir = baseDir;
14
- this.pretty = pretty;
15
- this.hashAlgorithm = hashAlgorithm;
5
+ #VERSION = Utils.getORMVersion();
6
+ #cache = {};
7
+ #options;
8
+ #baseDir;
9
+ #pretty;
10
+ constructor(options = {}, baseDir, pretty = false) {
11
+ this.#options = options;
12
+ this.#baseDir = baseDir;
13
+ this.#pretty = pretty;
14
+ this.#options.cacheDir ??= process.cwd() + '/temp';
16
15
  }
17
16
  /**
18
17
  * @inheritDoc
@@ -22,7 +21,7 @@ export class FileCacheAdapter {
22
21
  if (!existsSync(path)) {
23
22
  return null;
24
23
  }
25
- const payload = Utils.readJSONSync(path);
24
+ const payload = fs.readJSONSync(path);
26
25
  const hash = this.getHash(payload.origin);
27
26
  if (!hash || payload.hash !== hash) {
28
27
  return null;
@@ -33,13 +32,13 @@ export class FileCacheAdapter {
33
32
  * @inheritDoc
34
33
  */
35
34
  set(name, data, origin) {
36
- if (this.options.combined) {
37
- this.cache[name.replace(/\.[jt]s$/, '')] = data;
35
+ if (this.#options.combined) {
36
+ this.#cache[name.replace(/\.[jt]s$/, '')] = data;
38
37
  return;
39
38
  }
40
39
  const path = this.path(name);
41
40
  const hash = this.getHash(origin);
42
- writeFileSync(path, JSON.stringify({ data, origin, hash, version: this.VERSION }, null, this.pretty ? 2 : undefined));
41
+ writeFileSync(path, JSON.stringify({ data, origin, hash, version: this.#VERSION }, null, this.#pretty ? 2 : undefined));
43
42
  }
44
43
  /**
45
44
  * @inheritDoc
@@ -53,32 +52,38 @@ export class FileCacheAdapter {
53
52
  */
54
53
  clear() {
55
54
  const path = this.path('*');
56
- const files = globSync(path);
57
- files.forEach(file => unlinkSync(file));
58
- this.cache = {};
55
+ const files = fs.glob(path);
56
+ for (const file of files) {
57
+ /* v8 ignore next */
58
+ try {
59
+ unlinkSync(file);
60
+ }
61
+ catch {
62
+ // ignore if file is already gone
63
+ }
64
+ }
65
+ this.#cache = {};
59
66
  }
60
67
  combine() {
61
- if (!this.options.combined) {
68
+ if (!this.#options.combined) {
62
69
  return;
63
70
  }
64
- let path = typeof this.options.combined === 'string'
65
- ? this.options.combined
66
- : './metadata.json';
67
- path = Utils.normalizePath(this.options.cacheDir, path);
68
- this.options.combined = path; // override in the options, so we can log it from the CLI in `cache:generate` command
69
- writeFileSync(path, JSON.stringify(this.cache, null, this.pretty ? 2 : undefined));
71
+ let path = typeof this.#options.combined === 'string' ? this.#options.combined : './metadata.json';
72
+ path = fs.normalizePath(this.#options.cacheDir, path);
73
+ this.#options.combined = path; // override in the options, so we can log it from the CLI in `cache:generate` command
74
+ writeFileSync(path, JSON.stringify(this.#cache, null, this.#pretty ? 2 : undefined));
70
75
  return path;
71
76
  }
72
77
  path(name) {
73
- Utils.ensureDir(this.options.cacheDir);
74
- return `${this.options.cacheDir}/${name}.json`;
78
+ fs.ensureDir(this.#options.cacheDir);
79
+ return `${this.#options.cacheDir}/${name}.json`;
75
80
  }
76
81
  getHash(origin) {
77
- origin = Utils.absolutePath(origin, this.baseDir);
82
+ origin = fs.absolutePath(origin, this.#baseDir);
78
83
  if (!existsSync(origin)) {
79
84
  return null;
80
85
  }
81
86
  const contents = readFileSync(origin);
82
- return Utils.hash(contents.toString() + this.VERSION, undefined, this.hashAlgorithm);
87
+ return Utils.hash(contents.toString() + this.#VERSION);
83
88
  }
84
89
  }
@@ -1,8 +1,7 @@
1
1
  import type { CacheAdapter } from './CacheAdapter.js';
2
2
  import type { Dictionary } from '../typings.js';
3
3
  export declare class GeneratedCacheAdapter implements CacheAdapter {
4
- private readonly options;
5
- private readonly data;
4
+ #private;
6
5
  constructor(options: {
7
6
  data: Dictionary;
8
7
  });
@@ -1,34 +1,32 @@
1
1
  export class GeneratedCacheAdapter {
2
- options;
3
- data = new Map();
2
+ #data;
4
3
  constructor(options) {
5
- this.options = options;
6
- this.data = new Map(Object.entries(options.data));
4
+ this.#data = new Map(Object.entries(options.data));
7
5
  }
8
6
  /**
9
7
  * @inheritDoc
10
8
  */
11
9
  get(name) {
12
10
  const key = name.replace(/\.[jt]s$/, '');
13
- const data = this.data.get(key);
11
+ const data = this.#data.get(key);
14
12
  return data;
15
13
  }
16
14
  /**
17
15
  * @inheritDoc
18
16
  */
19
17
  set(name, data, origin) {
20
- this.data.set(name, { data });
18
+ this.#data.set(name, { data });
21
19
  }
22
20
  /**
23
21
  * @inheritDoc
24
22
  */
25
23
  remove(name) {
26
- this.data.delete(name);
24
+ this.#data.delete(name);
27
25
  }
28
26
  /**
29
27
  * @inheritDoc
30
28
  */
31
29
  clear() {
32
- this.data.clear();
30
+ this.#data.clear();
33
31
  }
34
32
  }
@@ -1,7 +1,6 @@
1
1
  import type { CacheAdapter } from './CacheAdapter.js';
2
2
  export declare class MemoryCacheAdapter implements CacheAdapter {
3
- private readonly options;
4
- private readonly data;
3
+ #private;
5
4
  constructor(options: {
6
5
  expiration: number;
7
6
  });
@@ -1,17 +1,17 @@
1
1
  export class MemoryCacheAdapter {
2
- options;
3
- data = new Map();
2
+ #data = new Map();
3
+ #options;
4
4
  constructor(options) {
5
- this.options = options;
5
+ this.#options = options;
6
6
  }
7
7
  /**
8
8
  * @inheritDoc
9
9
  */
10
10
  get(name) {
11
- const data = this.data.get(name);
11
+ const data = this.#data.get(name);
12
12
  if (data) {
13
13
  if (data.expiration < Date.now()) {
14
- this.data.delete(name);
14
+ this.#data.delete(name);
15
15
  }
16
16
  else {
17
17
  return data.data;
@@ -23,18 +23,18 @@ export class MemoryCacheAdapter {
23
23
  * @inheritDoc
24
24
  */
25
25
  set(name, data, origin, expiration) {
26
- this.data.set(name, { data, expiration: Date.now() + (expiration ?? this.options.expiration) });
26
+ this.#data.set(name, { data, expiration: Date.now() + (expiration ?? this.#options.expiration) });
27
27
  }
28
28
  /**
29
29
  * @inheritDoc
30
30
  */
31
31
  remove(name) {
32
- this.data.delete(name);
32
+ this.#data.delete(name);
33
33
  }
34
34
  /**
35
35
  * @inheritDoc
36
36
  */
37
37
  clear() {
38
- this.data.clear();
38
+ this.#data.clear();
39
39
  }
40
40
  }
package/cache/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- export * from './CacheAdapter.js';
1
+ export type * from './CacheAdapter.js';
2
2
  export * from './NullCacheAdapter.js';
3
- export * from './FileCacheAdapter.js';
4
3
  export * from './MemoryCacheAdapter.js';
5
4
  export * from './GeneratedCacheAdapter.js';
package/cache/index.js CHANGED
@@ -1,5 +1,3 @@
1
- export * from './CacheAdapter.js';
2
1
  export * from './NullCacheAdapter.js';
3
- export * from './FileCacheAdapter.js';
4
2
  export * from './MemoryCacheAdapter.js';
5
3
  export * from './GeneratedCacheAdapter.js';
@@ -17,7 +17,9 @@ export declare abstract class Connection {
17
17
  /**
18
18
  * Establishes connection to database
19
19
  */
20
- abstract connect(): void | Promise<void>;
20
+ abstract connect(options?: {
21
+ skipOnConnect?: boolean;
22
+ }): void | Promise<void>;
21
23
  /**
22
24
  * Are we connected to the database
23
25
  */
@@ -37,18 +39,24 @@ export declare abstract class Connection {
37
39
  */
38
40
  close(force?: boolean): Promise<void>;
39
41
  /**
40
- * Ensure the connection exists, this is used to support lazy connect when using `MikroORM.initSync()`
42
+ * Ensure the connection exists, this is used to support lazy connect when using `new MikroORM()` instead of the async `init` method.
41
43
  */
42
44
  ensureConnection(): Promise<void>;
45
+ /**
46
+ * Execute raw SQL queries, handy from running schema dump loaded from a file.
47
+ * This method doesn't support transactions, as opposed to `orm.schema.execute()`, which is used internally.
48
+ */
49
+ executeDump(dump: string): Promise<void>;
50
+ protected onConnect(): Promise<void>;
43
51
  transactional<T>(cb: (trx: Transaction) => Promise<T>, options?: {
44
- isolationLevel?: IsolationLevel;
52
+ isolationLevel?: IsolationLevel | `${IsolationLevel}`;
45
53
  readOnly?: boolean;
46
54
  ctx?: Transaction;
47
55
  eventBroadcaster?: TransactionEventBroadcaster;
48
56
  loggerContext?: LogContext;
49
57
  }): Promise<T>;
50
58
  begin(options?: {
51
- isolationLevel?: IsolationLevel;
59
+ isolationLevel?: IsolationLevel | `${IsolationLevel}`;
52
60
  readOnly?: boolean;
53
61
  ctx?: Transaction;
54
62
  eventBroadcaster?: TransactionEventBroadcaster;
@@ -58,7 +66,6 @@ export declare abstract class Connection {
58
66
  rollback(ctx: Transaction, eventBroadcaster?: TransactionEventBroadcaster, loggerContext?: LogContext): Promise<void>;
59
67
  abstract execute<T>(query: string, params?: any[], method?: 'all' | 'get' | 'run', ctx?: Transaction): Promise<QueryResult<T> | any | any[]>;
60
68
  getConnectionOptions(): ConnectionConfig;
61
- getClientUrl(): string;
62
69
  setMetadata(metadata: MetadataStorage): void;
63
70
  setPlatform(platform: Platform): void;
64
71
  getPlatform(): Platform;
@@ -1,4 +1,3 @@
1
- import { URL } from 'node:url';
2
1
  import { Utils } from '../utils/Utils.js';
3
2
  export class Connection {
4
3
  config;
@@ -17,7 +16,18 @@ export class Connection {
17
16
  this.options = Utils.copy(options);
18
17
  }
19
18
  else {
20
- const props = ['dbName', 'clientUrl', 'host', 'port', 'user', 'password', 'multipleStatements', 'pool', 'schema', 'driverOptions'];
19
+ const props = [
20
+ 'dbName',
21
+ 'clientUrl',
22
+ 'host',
23
+ 'port',
24
+ 'user',
25
+ 'password',
26
+ 'multipleStatements',
27
+ 'pool',
28
+ 'schema',
29
+ 'driverOptions',
30
+ ];
21
31
  this.options = props.reduce((o, i) => {
22
32
  o[i] = this.config.get(i);
23
33
  return o;
@@ -33,13 +43,32 @@ export class Connection {
33
43
  .forEach(k => delete this.options[k]);
34
44
  }
35
45
  /**
36
- * Ensure the connection exists, this is used to support lazy connect when using `MikroORM.initSync()`
46
+ * Ensure the connection exists, this is used to support lazy connect when using `new MikroORM()` instead of the async `init` method.
37
47
  */
38
48
  async ensureConnection() {
39
49
  if (!this.connected) {
40
50
  await this.connect();
41
51
  }
42
52
  }
53
+ /**
54
+ * Execute raw SQL queries, handy from running schema dump loaded from a file.
55
+ * This method doesn't support transactions, as opposed to `orm.schema.execute()`, which is used internally.
56
+ */
57
+ async executeDump(dump) {
58
+ throw new Error(`Executing SQL dumps is not supported by current driver`);
59
+ }
60
+ async onConnect() {
61
+ const schemaGenerator = this.config.getExtension('@mikro-orm/schema-generator');
62
+ if (this.type === 'write' && schemaGenerator) {
63
+ if (this.config.get('ensureDatabase')) {
64
+ const options = this.config.get('ensureDatabase');
65
+ await schemaGenerator.ensureDatabase(typeof options === 'boolean' ? {} : { ...options, forceCheck: true });
66
+ }
67
+ if (this.config.get('ensureIndexes')) {
68
+ await schemaGenerator.ensureIndexes();
69
+ }
70
+ }
71
+ }
43
72
  async transactional(cb, options) {
44
73
  throw new Error(`Transactions are not supported by current driver`);
45
74
  }
@@ -67,24 +96,17 @@ export class Connection {
67
96
  }
68
97
  }
69
98
  else {
70
- const url = new URL(this.config.getClientUrl());
99
+ const url = new URL(this.config.get('clientUrl'));
71
100
  this.options.host = ret.host = this.options.host ?? this.config.get('host', decodeURIComponent(url.hostname));
72
101
  this.options.port = ret.port = this.options.port ?? this.config.get('port', +url.port);
73
102
  this.options.user = ret.user = this.options.user ?? this.config.get('user', decodeURIComponent(url.username));
74
- this.options.password = ret.password = this.options.password ?? this.config.get('password', decodeURIComponent(url.password));
75
- this.options.dbName = ret.database = this.options.dbName ?? this.config.get('dbName', decodeURIComponent(url.pathname).replace(/^\//, ''));
103
+ this.options.password = ret.password =
104
+ this.options.password ?? this.config.get('password', decodeURIComponent(url.password));
105
+ this.options.dbName = ret.database =
106
+ this.options.dbName ?? this.config.get('dbName', decodeURIComponent(url.pathname).replace(/^\//, ''));
76
107
  }
77
108
  return ret;
78
109
  }
79
- getClientUrl() {
80
- const options = this.getConnectionOptions();
81
- const url = new URL(this.config.getClientUrl(true));
82
- const password = options.password ? ':*****' : '';
83
- const schema = options.schema && options.schema !== this.platform.getDefaultSchemaName()
84
- ? `?schema=${options.schema}`
85
- : '';
86
- return `${url.protocol}//${options.user}${password}@${options.host}:${options.port}${schema}`;
87
- }
88
110
  setMetadata(metadata) {
89
111
  this.metadata = metadata;
90
112
  }
@@ -1,5 +1,5 @@
1
- import { type CountOptions, type DeleteOptions, type DriverMethodOptions, EntityManagerType, type FindOneOptions, type FindOptions, type IDatabaseDriver, type LockOptions, type NativeInsertUpdateManyOptions, type NativeInsertUpdateOptions, type OrderDefinition } from './IDatabaseDriver.js';
2
- import type { ConnectionType, Dictionary, EntityData, EntityDictionary, EntityMetadata, EntityProperty, FilterQuery, PopulateOptions, Primary } from '../typings.js';
1
+ import { type CountOptions, type DeleteOptions, type DriverMethodOptions, EntityManagerType, type FindOneOptions, type FindOptions, type IDatabaseDriver, type LockOptions, type NativeInsertUpdateManyOptions, type NativeInsertUpdateOptions, type OrderDefinition, type StreamOptions } from './IDatabaseDriver.js';
2
+ import type { ConnectionType, Constructor, Dictionary, EntityData, EntityDictionary, EntityMetadata, EntityName, EntityProperty, FilterQuery, PopulateOptions, Primary } from '../typings.js';
3
3
  import type { MetadataStorage } from '../metadata/MetadataStorage.js';
4
4
  import type { Connection, QueryResult, Transaction } from '../connections/Connection.js';
5
5
  import { type Configuration, type ConnectionOptions } from '../utils/Configuration.js';
@@ -9,7 +9,7 @@ import type { Platform } from '../platforms/Platform.js';
9
9
  import type { Collection } from '../entity/Collection.js';
10
10
  import { EntityManager } from '../EntityManager.js';
11
11
  import { DriverException } from '../exceptions.js';
12
- import type { Logger } from '../logging/Logger.js';
12
+ import { MikroORM } from '../MikroORM.js';
13
13
  export declare abstract class DatabaseDriver<C extends Connection> implements IDatabaseDriver<C> {
14
14
  readonly config: Configuration;
15
15
  protected readonly dependencies: string[];
@@ -17,33 +17,37 @@ export declare abstract class DatabaseDriver<C extends Connection> implements ID
17
17
  protected readonly connection: C;
18
18
  protected readonly replicas: C[];
19
19
  protected readonly platform: Platform;
20
- protected readonly logger: Logger;
21
20
  protected comparator: EntityComparator;
22
21
  protected metadata: MetadataStorage;
23
22
  protected constructor(config: Configuration, dependencies: string[]);
24
- abstract find<T extends object, P extends string = never, F extends string = '*', E extends string = never>(entityName: string, where: FilterQuery<T>, options?: FindOptions<T, P, F, E>): Promise<EntityData<T>[]>;
25
- abstract findOne<T extends object, P extends string = never, F extends string = '*', E extends string = never>(entityName: string, where: FilterQuery<T>, options?: FindOneOptions<T, P, F, E>): Promise<EntityData<T> | null>;
26
- abstract nativeInsert<T extends object>(entityName: string, data: EntityDictionary<T>, options?: NativeInsertUpdateOptions<T>): Promise<QueryResult<T>>;
27
- abstract nativeInsertMany<T extends object>(entityName: string, data: EntityDictionary<T>[], options?: NativeInsertUpdateManyOptions<T>, transform?: (sql: string) => string): Promise<QueryResult<T>>;
28
- abstract nativeUpdate<T extends object>(entityName: string, where: FilterQuery<T>, data: EntityDictionary<T>, options?: NativeInsertUpdateOptions<T>): Promise<QueryResult<T>>;
29
- nativeUpdateMany<T extends object>(entityName: string, where: FilterQuery<T>[], data: EntityDictionary<T>[], options?: NativeInsertUpdateManyOptions<T>): Promise<QueryResult<T>>;
30
- abstract nativeDelete<T extends object>(entityName: string, where: FilterQuery<T>, options?: DeleteOptions<T>): Promise<QueryResult<T>>;
31
- abstract count<T extends object, P extends string = never>(entityName: string, where: FilterQuery<T>, options?: CountOptions<T, P>): Promise<number>;
23
+ abstract find<T extends object, P extends string = never, F extends string = '*', E extends string = never>(entityName: EntityName<T>, where: FilterQuery<T>, options?: FindOptions<T, P, F, E>): Promise<EntityData<T>[]>;
24
+ abstract findOne<T extends object, P extends string = never, F extends string = '*', E extends string = never>(entityName: EntityName<T>, where: FilterQuery<T>, options?: FindOneOptions<T, P, F, E>): Promise<EntityData<T> | null>;
25
+ abstract nativeInsert<T extends object>(entityName: EntityName<T>, data: EntityDictionary<T>, options?: NativeInsertUpdateOptions<T>): Promise<QueryResult<T>>;
26
+ abstract nativeInsertMany<T extends object>(entityName: EntityName<T>, data: EntityDictionary<T>[], options?: NativeInsertUpdateManyOptions<T>, transform?: (sql: string) => string): Promise<QueryResult<T>>;
27
+ abstract nativeUpdate<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, data: EntityDictionary<T>, options?: NativeInsertUpdateOptions<T>): Promise<QueryResult<T>>;
28
+ nativeUpdateMany<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>[], data: EntityDictionary<T>[], options?: NativeInsertUpdateManyOptions<T>): Promise<QueryResult<T>>;
29
+ abstract nativeDelete<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, options?: DeleteOptions<T>): Promise<QueryResult<T>>;
30
+ abstract count<T extends object, P extends string = never>(entityName: EntityName<T>, where: FilterQuery<T>, options?: CountOptions<T, P>): Promise<number>;
32
31
  createEntityManager(useContext?: boolean): this[typeof EntityManagerType];
33
- findVirtual<T extends object>(entityName: string, where: FilterQuery<T>, options: FindOptions<T, any, any, any>): Promise<EntityData<T>[]>;
34
- countVirtual<T extends object>(entityName: string, where: FilterQuery<T>, options: CountOptions<T, any>): Promise<number>;
35
- aggregate(entityName: string, pipeline: any[]): Promise<any[]>;
32
+ findVirtual<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, options: FindOptions<T, any, any, any>): Promise<EntityData<T>[]>;
33
+ countVirtual<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, options: CountOptions<T, any>): Promise<number>;
34
+ aggregate(entityName: EntityName, pipeline: any[]): Promise<any[]>;
36
35
  loadFromPivotTable<T extends object, O extends object>(prop: EntityProperty, owners: Primary<O>[][], where?: FilterQuery<any>, orderBy?: OrderDefinition<T>, ctx?: Transaction, options?: FindOptions<T, any, any, any>, pivotJoin?: boolean): Promise<Dictionary<T[]>>;
37
36
  syncCollections<T extends object, O extends object>(collections: Iterable<Collection<T, O>>, options?: DriverMethodOptions): Promise<void>;
38
37
  mapResult<T extends object>(result: EntityDictionary<T>, meta?: EntityMetadata<T>, populate?: PopulateOptions<T>[]): EntityData<T> | null;
39
- connect(): Promise<C>;
40
- reconnect(): Promise<C>;
38
+ connect(options?: {
39
+ skipOnConnect?: boolean;
40
+ }): Promise<C>;
41
+ reconnect(options?: {
42
+ skipOnConnect?: boolean;
43
+ }): Promise<C>;
41
44
  getConnection(type?: ConnectionType): C;
42
45
  close(force?: boolean): Promise<void>;
43
46
  getPlatform(): Platform;
44
47
  setMetadata(metadata: MetadataStorage): void;
45
48
  getMetadata(): MetadataStorage;
46
49
  getDependencies(): string[];
50
+ protected isPopulated<T extends object>(meta: EntityMetadata<T>, prop: EntityProperty<T>, hint: PopulateOptions<T>, name?: string): boolean;
47
51
  protected processCursorOptions<T extends object, P extends string>(meta: EntityMetadata<T>, options: FindOptions<T, P, any, any>, orderBy: OrderDefinition<T>): {
48
52
  orderBy: OrderDefinition<T>[];
49
53
  where: FilterQuery<T>;
@@ -52,9 +56,10 @@ export declare abstract class DatabaseDriver<C extends Connection> implements ID
52
56
  /** @internal */
53
57
  mapDataToFieldNames(data: Dictionary, stringifyJsonArrays: boolean, properties?: Record<string, EntityProperty>, convertCustomTypes?: boolean, object?: boolean): Dictionary;
54
58
  protected inlineEmbeddables<T extends object>(meta: EntityMetadata<T>, data: T, where?: boolean): void;
55
- protected getPrimaryKeyFields(entityName: string): string[];
59
+ protected getPrimaryKeyFields<T>(meta: EntityMetadata<T>): string[];
56
60
  protected createReplicas(cb: (c: ConnectionOptions) => C): C[];
57
61
  lockPessimistic<T extends object>(entity: T, options: LockOptions): Promise<void>;
62
+ abstract stream<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, options: StreamOptions<T>): AsyncIterableIterator<T>;
58
63
  /**
59
64
  * @inheritDoc
60
65
  */
@@ -71,4 +76,6 @@ export declare abstract class DatabaseDriver<C extends Connection> implements ID
71
76
  schema?: string;
72
77
  parentSchema?: string;
73
78
  }): string | undefined;
79
+ /** @internal */
80
+ getORMClass(): Constructor<MikroORM>;
74
81
  }