-
Notifications
You must be signed in to change notification settings - Fork 3
/
_db.js
36 lines (31 loc) · 849 Bytes
/
_db.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"use strict";
const config = require("./config");
const fs = require("fs");
const path = require("path");
const sequelize = require("sequelize");
const modelsPath = path.join(__dirname, "/models/");
var connection = new sequelize(config.db.database, config.db.user, config.db.password, {
host: config.db.host,
dialect: config.db.dialect,
pool: {
max: 5,
min: 0,
idle: 10000
}
});
var db = {};
fs
.readdirSync(modelsPath)
.filter(function(file) {
return (file.indexOf(".") > 0);
})
.forEach(function(file) {
var model = connection.import(path.join(modelsPath, file));
db[model.name] = model;
});
Object.keys(db).forEach(function(modelName) {
if ("associate" in db[modelName]) {
db[modelName].associate(db);
}
});
module.exports = connection;