-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.js
42 lines (41 loc) · 1.35 KB
/
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
37
38
39
40
41
42
//======================================================================================
var fs = require('fs');
var path = require('path');
var Sequelize = require('sequelize');
//--------------------------------------------------------------------------------------
var config = {
database : 'ZCHAT',
username : 'zsh',
password : 'aq1sw2de',
host : 'localhost',
dialect : 'mysql',
port : '3306',
dialectOptions : {
insecureAuth : "true"
}
};
var sequelize = new Sequelize(config.database, config.username, config.password, config);
var db = {};
//--------------------------------------------------------------------------------------
fs.readdirSync(__dirname+'/models')
.filter (
function(file) {
return (file.indexOf(".") !== 0);
})
.forEach(
function(file) {
var model = sequelize["import"](path.join(__dirname+'/models', file));
db[model.name] = model;
});
Object.keys(db).forEach(
function(modelName) {
if ("associate" in db[modelName]) {
db[modelName].associate(db);
}
});
//--------------------------------------------------------------------------------------
db.sequelize = sequelize;
db.Sequelize = Sequelize;
//======================================================================================
module.exports = db;
//======================================================================================