mm-share-lib 0.0.26 → 0.0.28
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/package.json
CHANGED
@@ -1,26 +1,21 @@
|
|
1
|
-
import { DataSource } from 'typeorm';
|
2
|
-
import { ConfigService } from '@nestjs/config';
|
3
|
-
import { DatabaseConfig } from '../../config';
|
1
|
+
import { DataSource, DataSourceOptions } from 'typeorm';
|
4
2
|
|
5
3
|
export class DataSourceManager {
|
6
4
|
private static instance: DataSourceManager;
|
7
5
|
|
8
|
-
private dataSources: { [key: string]: DataSource };
|
6
|
+
private readonly dataSources: { [key: string]: DataSource } = {};
|
9
7
|
|
10
|
-
private constructor(private
|
11
|
-
this.dataSources = {};
|
12
|
-
}
|
8
|
+
private constructor(private options: DataSourceOptions) {}
|
13
9
|
|
14
|
-
public static getInstance(): DataSourceManager {
|
10
|
+
public static getInstance(options: DataSourceOptions): DataSourceManager {
|
15
11
|
if (!DataSourceManager.instance) {
|
16
|
-
|
17
|
-
// DataSourceManager.instance = new DataSourceManager();
|
12
|
+
DataSourceManager.instance = new DataSourceManager(options);
|
18
13
|
}
|
19
14
|
|
20
15
|
return DataSourceManager.instance;
|
21
16
|
}
|
22
17
|
|
23
|
-
async
|
18
|
+
async getDataSource(dataSourceName: string): Promise<DataSource> {
|
24
19
|
if (this.dataSources[dataSourceName]) {
|
25
20
|
const dataSource = this.dataSources[dataSourceName];
|
26
21
|
return dataSource.isInitialized
|
@@ -28,12 +23,10 @@ export class DataSourceManager {
|
|
28
23
|
: await dataSource.initialize();
|
29
24
|
}
|
30
25
|
|
31
|
-
const newDataSource = new DataSource(
|
32
|
-
/** connection info */
|
33
|
-
} as any);
|
26
|
+
const newDataSource = new DataSource(this.options);
|
34
27
|
|
35
28
|
this.dataSources[dataSourceName] = newDataSource;
|
36
29
|
|
37
|
-
return
|
30
|
+
return newDataSource.initialize();
|
38
31
|
}
|
39
32
|
}
|