@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.
- package/EntityManager.d.ts +70 -75
- package/EntityManager.js +487 -402
- package/MikroORM.d.ts +45 -38
- package/MikroORM.js +123 -156
- package/README.md +7 -4
- package/cache/FileCacheAdapter.d.ts +2 -7
- package/cache/FileCacheAdapter.js +35 -30
- package/cache/GeneratedCacheAdapter.d.ts +1 -2
- package/cache/GeneratedCacheAdapter.js +6 -8
- package/cache/MemoryCacheAdapter.d.ts +1 -2
- package/cache/MemoryCacheAdapter.js +8 -8
- package/cache/index.d.ts +1 -2
- package/cache/index.js +0 -2
- package/connections/Connection.d.ts +12 -5
- package/connections/Connection.js +37 -15
- package/drivers/DatabaseDriver.d.ts +25 -18
- package/drivers/DatabaseDriver.js +144 -45
- package/drivers/IDatabaseDriver.d.ts +118 -23
- package/entity/BaseEntity.d.ts +63 -4
- package/entity/BaseEntity.js +0 -3
- package/entity/Collection.d.ts +95 -31
- package/entity/Collection.js +487 -139
- package/entity/EntityAssigner.js +37 -25
- package/entity/EntityFactory.d.ts +8 -9
- package/entity/EntityFactory.js +152 -100
- package/entity/EntityHelper.d.ts +2 -2
- package/entity/EntityHelper.js +69 -27
- package/entity/EntityLoader.d.ts +12 -13
- package/entity/EntityLoader.js +286 -125
- package/entity/EntityRepository.d.ts +28 -8
- package/entity/EntityRepository.js +8 -2
- package/entity/PolymorphicRef.d.ts +12 -0
- package/entity/PolymorphicRef.js +18 -0
- package/entity/Reference.d.ts +3 -8
- package/entity/Reference.js +62 -29
- package/entity/WrappedEntity.d.ts +7 -10
- package/entity/WrappedEntity.js +6 -7
- package/entity/defineEntity.d.ts +472 -313
- package/entity/defineEntity.js +134 -290
- package/entity/index.d.ts +2 -2
- package/entity/index.js +2 -2
- package/entity/utils.d.ts +6 -1
- package/entity/utils.js +46 -11
- package/entity/validators.d.ts +11 -0
- package/entity/validators.js +66 -0
- package/enums.d.ts +8 -6
- package/enums.js +13 -17
- package/errors.d.ts +26 -16
- package/errors.js +63 -31
- package/events/EventManager.d.ts +3 -5
- package/events/EventManager.js +37 -26
- package/events/index.d.ts +1 -1
- package/events/index.js +0 -1
- package/exceptions.js +9 -2
- package/hydration/Hydrator.js +1 -2
- package/hydration/ObjectHydrator.d.ts +5 -6
- package/hydration/ObjectHydrator.js +109 -50
- package/index.d.ts +2 -2
- package/index.js +1 -2
- package/logging/DefaultLogger.d.ts +1 -1
- package/logging/DefaultLogger.js +3 -4
- package/logging/SimpleLogger.d.ts +1 -1
- package/logging/colors.d.ts +1 -1
- package/logging/colors.js +4 -6
- package/logging/index.d.ts +2 -1
- package/logging/index.js +1 -1
- package/logging/inspect.d.ts +2 -0
- package/logging/inspect.js +11 -0
- package/metadata/EntitySchema.d.ts +47 -23
- package/metadata/EntitySchema.js +103 -34
- package/metadata/MetadataDiscovery.d.ts +65 -18
- package/metadata/MetadataDiscovery.js +940 -424
- package/metadata/MetadataProvider.d.ts +11 -2
- package/metadata/MetadataProvider.js +71 -2
- package/metadata/MetadataStorage.d.ts +11 -13
- package/metadata/MetadataStorage.js +79 -48
- package/metadata/MetadataValidator.d.ts +32 -9
- package/metadata/MetadataValidator.js +214 -44
- package/metadata/discover-entities.d.ts +5 -0
- package/metadata/discover-entities.js +40 -0
- package/metadata/index.d.ts +1 -1
- package/metadata/index.js +0 -1
- package/metadata/types.d.ts +577 -0
- package/metadata/types.js +1 -0
- package/naming-strategy/AbstractNamingStrategy.d.ts +16 -4
- package/naming-strategy/AbstractNamingStrategy.js +26 -5
- package/naming-strategy/EntityCaseNamingStrategy.d.ts +3 -3
- package/naming-strategy/EntityCaseNamingStrategy.js +7 -6
- package/naming-strategy/MongoNamingStrategy.d.ts +3 -3
- package/naming-strategy/MongoNamingStrategy.js +6 -6
- package/naming-strategy/NamingStrategy.d.ts +28 -4
- package/naming-strategy/UnderscoreNamingStrategy.d.ts +3 -3
- package/naming-strategy/UnderscoreNamingStrategy.js +6 -6
- package/naming-strategy/index.d.ts +1 -1
- package/naming-strategy/index.js +0 -1
- package/not-supported.d.ts +2 -0
- package/not-supported.js +8 -0
- package/package.json +47 -36
- package/platforms/ExceptionConverter.js +1 -1
- package/platforms/Platform.d.ts +33 -15
- package/platforms/Platform.js +125 -69
- package/serialization/EntitySerializer.d.ts +6 -3
- package/serialization/EntitySerializer.js +54 -30
- package/serialization/EntityTransformer.js +37 -22
- package/serialization/SerializationContext.d.ts +10 -14
- package/serialization/SerializationContext.js +24 -19
- package/types/ArrayType.d.ts +1 -1
- package/types/ArrayType.js +2 -3
- package/types/BigIntType.js +1 -1
- package/types/BlobType.d.ts +0 -1
- package/types/BlobType.js +0 -3
- package/types/BooleanType.d.ts +1 -0
- package/types/BooleanType.js +3 -0
- package/types/DecimalType.js +2 -2
- package/types/DoubleType.js +1 -1
- package/types/EnumArrayType.js +1 -2
- package/types/JsonType.d.ts +1 -1
- package/types/JsonType.js +7 -2
- package/types/TinyIntType.js +1 -1
- package/types/Type.d.ts +2 -4
- package/types/Type.js +3 -3
- package/types/Uint8ArrayType.d.ts +0 -1
- package/types/Uint8ArrayType.js +1 -4
- package/types/UuidType.d.ts +2 -0
- package/types/UuidType.js +14 -2
- package/types/index.d.ts +3 -2
- package/typings.d.ts +427 -170
- package/typings.js +100 -45
- package/unit-of-work/ChangeSet.d.ts +4 -6
- package/unit-of-work/ChangeSet.js +8 -9
- package/unit-of-work/ChangeSetComputer.d.ts +2 -12
- package/unit-of-work/ChangeSetComputer.js +61 -38
- package/unit-of-work/ChangeSetPersister.d.ts +10 -17
- package/unit-of-work/ChangeSetPersister.js +136 -73
- package/unit-of-work/CommitOrderCalculator.d.ts +13 -14
- package/unit-of-work/CommitOrderCalculator.js +22 -20
- package/unit-of-work/IdentityMap.d.ts +12 -3
- package/unit-of-work/IdentityMap.js +51 -13
- package/unit-of-work/UnitOfWork.d.ts +39 -23
- package/unit-of-work/UnitOfWork.js +441 -246
- package/utils/AbstractMigrator.d.ts +101 -0
- package/utils/AbstractMigrator.js +303 -0
- package/utils/AbstractSchemaGenerator.d.ts +5 -5
- package/utils/AbstractSchemaGenerator.js +30 -18
- package/utils/AsyncContext.d.ts +6 -0
- package/utils/AsyncContext.js +42 -0
- package/utils/Configuration.d.ts +647 -185
- package/utils/Configuration.js +215 -252
- package/utils/ConfigurationLoader.d.ts +1 -52
- package/utils/ConfigurationLoader.js +1 -330
- package/utils/Cursor.d.ts +3 -6
- package/utils/Cursor.js +32 -17
- package/utils/DataloaderUtils.d.ts +10 -5
- package/utils/DataloaderUtils.js +42 -22
- package/utils/EntityComparator.d.ts +21 -21
- package/utils/EntityComparator.js +224 -118
- package/utils/QueryHelper.d.ts +34 -7
- package/utils/QueryHelper.js +183 -72
- package/utils/RawQueryFragment.d.ts +28 -34
- package/utils/RawQueryFragment.js +37 -72
- package/utils/RequestContext.js +2 -2
- package/utils/TransactionContext.js +2 -2
- package/utils/TransactionManager.js +11 -8
- package/utils/Utils.d.ts +16 -127
- package/utils/Utils.js +104 -402
- package/utils/clone.js +13 -23
- package/utils/env-vars.d.ts +7 -0
- package/utils/env-vars.js +98 -0
- package/utils/fs-utils.d.ts +20 -0
- package/utils/fs-utils.js +193 -0
- package/utils/index.d.ts +1 -3
- package/utils/index.js +1 -3
- package/utils/upsert-utils.d.ts +9 -4
- package/utils/upsert-utils.js +51 -5
- package/decorators/Check.d.ts +0 -3
- package/decorators/Check.js +0 -13
- package/decorators/CreateRequestContext.d.ts +0 -3
- package/decorators/CreateRequestContext.js +0 -32
- package/decorators/Embeddable.d.ts +0 -8
- package/decorators/Embeddable.js +0 -11
- package/decorators/Embedded.d.ts +0 -12
- package/decorators/Embedded.js +0 -18
- package/decorators/Entity.d.ts +0 -33
- package/decorators/Entity.js +0 -12
- package/decorators/Enum.d.ts +0 -9
- package/decorators/Enum.js +0 -16
- package/decorators/Filter.d.ts +0 -2
- package/decorators/Filter.js +0 -8
- package/decorators/Formula.d.ts +0 -4
- package/decorators/Formula.js +0 -15
- package/decorators/Indexed.d.ts +0 -19
- package/decorators/Indexed.js +0 -20
- package/decorators/ManyToMany.d.ts +0 -42
- package/decorators/ManyToMany.js +0 -14
- package/decorators/ManyToOne.d.ts +0 -34
- package/decorators/ManyToOne.js +0 -14
- package/decorators/OneToMany.d.ts +0 -28
- package/decorators/OneToMany.js +0 -17
- package/decorators/OneToOne.d.ts +0 -28
- package/decorators/OneToOne.js +0 -7
- package/decorators/PrimaryKey.d.ts +0 -8
- package/decorators/PrimaryKey.js +0 -20
- package/decorators/Property.d.ts +0 -250
- package/decorators/Property.js +0 -32
- package/decorators/Transactional.d.ts +0 -14
- package/decorators/Transactional.js +0 -28
- package/decorators/hooks.d.ts +0 -16
- package/decorators/hooks.js +0 -47
- package/decorators/index.d.ts +0 -17
- package/decorators/index.js +0 -17
- package/entity/ArrayCollection.d.ts +0 -118
- package/entity/ArrayCollection.js +0 -407
- package/entity/EntityValidator.d.ts +0 -19
- package/entity/EntityValidator.js +0 -150
- package/metadata/ReflectMetadataProvider.d.ts +0 -8
- package/metadata/ReflectMetadataProvider.js +0 -44
- package/utils/resolveContextProvider.d.ts +0 -10
- 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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
this
|
|
13
|
-
this
|
|
14
|
-
this.
|
|
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 =
|
|
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
|
|
37
|
-
this
|
|
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
|
|
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 =
|
|
57
|
-
|
|
58
|
-
|
|
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
|
|
68
|
+
if (!this.#options.combined) {
|
|
62
69
|
return;
|
|
63
70
|
}
|
|
64
|
-
let path = typeof this
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
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
|
-
|
|
74
|
-
return `${this
|
|
78
|
+
fs.ensureDir(this.#options.cacheDir);
|
|
79
|
+
return `${this.#options.cacheDir}/${name}.json`;
|
|
75
80
|
}
|
|
76
81
|
getHash(origin) {
|
|
77
|
-
origin =
|
|
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
|
|
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
|
|
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
|
-
|
|
3
|
-
data = new Map();
|
|
2
|
+
#data;
|
|
4
3
|
constructor(options) {
|
|
5
|
-
this
|
|
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
|
|
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
|
|
18
|
+
this.#data.set(name, { data });
|
|
21
19
|
}
|
|
22
20
|
/**
|
|
23
21
|
* @inheritDoc
|
|
24
22
|
*/
|
|
25
23
|
remove(name) {
|
|
26
|
-
this
|
|
24
|
+
this.#data.delete(name);
|
|
27
25
|
}
|
|
28
26
|
/**
|
|
29
27
|
* @inheritDoc
|
|
30
28
|
*/
|
|
31
29
|
clear() {
|
|
32
|
-
this
|
|
30
|
+
this.#data.clear();
|
|
33
31
|
}
|
|
34
32
|
}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
export class MemoryCacheAdapter {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
#data = new Map();
|
|
3
|
+
#options;
|
|
4
4
|
constructor(options) {
|
|
5
|
-
this
|
|
5
|
+
this.#options = options;
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
8
|
* @inheritDoc
|
|
9
9
|
*/
|
|
10
10
|
get(name) {
|
|
11
|
-
const data = this
|
|
11
|
+
const data = this.#data.get(name);
|
|
12
12
|
if (data) {
|
|
13
13
|
if (data.expiration < Date.now()) {
|
|
14
|
-
this
|
|
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
|
|
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
|
|
32
|
+
this.#data.delete(name);
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
35
35
|
* @inheritDoc
|
|
36
36
|
*/
|
|
37
37
|
clear() {
|
|
38
|
-
this
|
|
38
|
+
this.#data.clear();
|
|
39
39
|
}
|
|
40
40
|
}
|
package/cache/index.d.ts
CHANGED
package/cache/index.js
CHANGED
|
@@ -17,7 +17,9 @@ export declare abstract class Connection {
|
|
|
17
17
|
/**
|
|
18
18
|
* Establishes connection to database
|
|
19
19
|
*/
|
|
20
|
-
abstract connect(
|
|
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
|
|
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 = [
|
|
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
|
|
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.
|
|
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 =
|
|
75
|
-
|
|
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
|
|
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:
|
|
25
|
-
abstract findOne<T extends object, P extends string = never, F extends string = '*', E extends string = never>(entityName:
|
|
26
|
-
abstract nativeInsert<T extends object>(entityName:
|
|
27
|
-
abstract nativeInsertMany<T extends object>(entityName:
|
|
28
|
-
abstract nativeUpdate<T extends object>(entityName:
|
|
29
|
-
nativeUpdateMany<T extends object>(entityName:
|
|
30
|
-
abstract nativeDelete<T extends object>(entityName:
|
|
31
|
-
abstract count<T extends object, P extends string = never>(entityName:
|
|
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:
|
|
34
|
-
countVirtual<T extends object>(entityName:
|
|
35
|
-
aggregate(entityName:
|
|
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(
|
|
40
|
-
|
|
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(
|
|
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
|
}
|