@midwayjs/core 3.4.9 → 3.4.10
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/dist/common/dataSourceManager.js +26 -28
- package/package.json +2 -2
|
@@ -18,38 +18,36 @@ class DataSourceManager {
|
|
|
18
18
|
}
|
|
19
19
|
async initDataSource(options, appDir) {
|
|
20
20
|
this.options = options;
|
|
21
|
-
if (options.dataSource) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
else {
|
|
37
|
-
// model will be add to array
|
|
38
|
-
entities.add(entity);
|
|
39
|
-
this.modelMapping.set(entity, dataSourceName);
|
|
21
|
+
if (!options.dataSource) {
|
|
22
|
+
throw new error_1.MidwayParameterError('DataSourceManager must set options.dataSource.');
|
|
23
|
+
}
|
|
24
|
+
for (const dataSourceName in options.dataSource) {
|
|
25
|
+
const dataSourceOptions = options.dataSource[dataSourceName];
|
|
26
|
+
if (dataSourceOptions['entities']) {
|
|
27
|
+
const entities = new Set();
|
|
28
|
+
// loop entities and glob files to model
|
|
29
|
+
for (const entity of dataSourceOptions['entities']) {
|
|
30
|
+
if (typeof entity === 'string') {
|
|
31
|
+
// string will be glob file
|
|
32
|
+
const models = globModels(entity, appDir);
|
|
33
|
+
for (const model of models) {
|
|
34
|
+
entities.add(model);
|
|
35
|
+
this.modelMapping.set(model, dataSourceName);
|
|
40
36
|
}
|
|
41
37
|
}
|
|
42
|
-
|
|
38
|
+
else {
|
|
39
|
+
// model will be add to array
|
|
40
|
+
entities.add(entity);
|
|
41
|
+
this.modelMapping.set(entity, dataSourceName);
|
|
42
|
+
}
|
|
43
43
|
}
|
|
44
|
-
|
|
45
|
-
const opts = {
|
|
46
|
-
cacheInstance: options.cacheInstance, // will default true
|
|
47
|
-
};
|
|
48
|
-
await this.createInstance(dataSourceOptions, dataSourceName, opts);
|
|
44
|
+
dataSourceOptions['entities'] = Array.from(entities);
|
|
49
45
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
46
|
+
// create data source
|
|
47
|
+
const opts = {
|
|
48
|
+
cacheInstance: options.cacheInstance, // will default true
|
|
49
|
+
};
|
|
50
|
+
await this.createInstance(dataSourceOptions, dataSourceName, opts);
|
|
53
51
|
}
|
|
54
52
|
}
|
|
55
53
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/core",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.10",
|
|
4
4
|
"description": "midway core",
|
|
5
5
|
"main": "dist/index",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"engines": {
|
|
46
46
|
"node": ">=12"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "aeb117633ecbc3299002b220f436dc3b5450d361"
|
|
49
49
|
}
|