@ccci/micro-server 1.0.35 → 1.0.37
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/index.js +23 -14
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -87557,20 +87557,23 @@ class DatabaseConnector {
|
|
|
87557
87557
|
DatabaseConnector.rootDir = path;
|
|
87558
87558
|
}
|
|
87559
87559
|
static async init() {
|
|
87560
|
-
|
|
87561
|
-
|
|
87562
|
-
|
|
87563
|
-
|
|
87564
|
-
|
|
87565
|
-
|
|
87566
|
-
|
|
87567
|
-
|
|
87568
|
-
|
|
87569
|
-
|
|
87570
|
-
|
|
87571
|
-
|
|
87560
|
+
return new Promise((resolve, reject) => {
|
|
87561
|
+
let connections = [];
|
|
87562
|
+
try {
|
|
87563
|
+
DatabaseConnector.connections = [];
|
|
87564
|
+
const configPath = `${DatabaseConnector.rootDir}/config/db.config.ts`;
|
|
87565
|
+
import(configPath).then((configs) => {
|
|
87566
|
+
const config = configs.default[env];
|
|
87567
|
+
const connection = new Sequelize(config);
|
|
87568
|
+
DatabaseConnector.connection = connection;
|
|
87569
|
+
connections.push(connection);
|
|
87570
|
+
});
|
|
87571
|
+
resolve(connections);
|
|
87572
|
+
} catch (error) {
|
|
87573
|
+
Logger.error(error);
|
|
87574
|
+
reject(connections);
|
|
87575
|
+
}
|
|
87572
87576
|
});
|
|
87573
|
-
return connections;
|
|
87574
87577
|
}
|
|
87575
87578
|
async initializeModels() {
|
|
87576
87579
|
let files = fs.readdirSync(`${DatabaseConnector.rootDir}/models`).filter((file) => file.indexOf(".") !== 0 && file.slice(-3) === ".ts");
|
|
@@ -87590,7 +87593,13 @@ class DatabaseConnector {
|
|
|
87590
87593
|
return DatabaseConnector.connection;
|
|
87591
87594
|
}
|
|
87592
87595
|
async connect(connection) {
|
|
87593
|
-
|
|
87596
|
+
try {
|
|
87597
|
+
Logger.info("Connecting to: ", connection);
|
|
87598
|
+
connection.authenticate();
|
|
87599
|
+
Logger.info("Connection to Database: Success!");
|
|
87600
|
+
} catch (error) {
|
|
87601
|
+
Logger.error(new Error("Connection to Database: ERROR!"));
|
|
87602
|
+
}
|
|
87594
87603
|
}
|
|
87595
87604
|
static getModel(modelName) {
|
|
87596
87605
|
return DatabaseConnector.connection.models[modelName];
|