dip-dobit-shared-model 1.0.0 → 1.0.3
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/config/config.js
CHANGED
package/models/dobitUser.js
CHANGED
package/models/index.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const Sequelize = require("sequelize");
|
|
6
|
+
const process = require("process");
|
|
7
|
+
const basename = path.basename(__filename);
|
|
8
|
+
const env = process.env.NODE_ENV || "development";
|
|
9
|
+
const config = require(__dirname + "/../config/config.js")[env];
|
|
10
|
+
const db = {};
|
|
11
|
+
|
|
12
|
+
let sequelize;
|
|
13
|
+
if (config.use_env_variable) {
|
|
14
|
+
sequelize = new Sequelize(process.env[config.use_env_variable], config);
|
|
15
|
+
} else {
|
|
16
|
+
sequelize = new Sequelize(
|
|
17
|
+
config.database,
|
|
18
|
+
config.username,
|
|
19
|
+
config.password,
|
|
20
|
+
config
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
fs.readdirSync(__dirname)
|
|
25
|
+
.filter((file) => {
|
|
26
|
+
return (
|
|
27
|
+
file.indexOf(".") !== 0 && file !== basename && file.slice(-3) === ".js"
|
|
28
|
+
);
|
|
29
|
+
})
|
|
30
|
+
.forEach((file) => {
|
|
31
|
+
const model = require(path.join(__dirname, file))(
|
|
32
|
+
sequelize,
|
|
33
|
+
Sequelize.DataTypes
|
|
34
|
+
);
|
|
35
|
+
db[model.name] = model;
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
Object.keys(db).forEach((modelName) => {
|
|
39
|
+
if (db[modelName].associate) {
|
|
40
|
+
db[modelName].associate(db);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
db.sequelize = sequelize;
|
|
45
|
+
db.Sequelize = Sequelize;
|
|
46
|
+
|
|
47
|
+
module.exports = db;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dip-dobit-shared-model",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"main": "index.js",
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"main": "models/index.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"migrate:up": "npx sequelize-cli db:migrate",
|
|
7
7
|
"migrate:undo": "npx sequelize-cli db:migrate:undo",
|
|
@@ -23,13 +23,8 @@
|
|
|
23
23
|
"description": "",
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"dotenv": "^17.2.3",
|
|
26
|
-
"module-alias": "^2.2.3",
|
|
27
26
|
"mysql2": "^3.15.3",
|
|
28
27
|
"sequelize": "^6.37.7",
|
|
29
28
|
"sequelize-cli": "^6.6.3"
|
|
30
|
-
},
|
|
31
|
-
"_moduleAliases": {
|
|
32
|
-
"@root": ".",
|
|
33
|
-
"@service": "service"
|
|
34
29
|
}
|
|
35
30
|
}
|