index.js 1.45 KB
Newer Older
1
import Sequelize from "sequelize";
2
import envs from "../../config/config";
3
4
5
6
import Doe from "../models/doe";
import Sgg from "../models/sgg";
import Emd from "../models/emd";
import User from "../models/user";
7
8
9
import Weather_In from "../models/weather_in";
import Weather_Out from "../models/weather_out";
import Data_Processing from "../models/data_processing";
10
11
12
13
14
15

// DB의 정보를 모두 담고 있는 객체 생성
const db = {};

// PostgreSQL과 연결된 Sequelize 객체 생성
const sequelize = new Sequelize(
16
17
18
  envs.db.database,
  envs.db.user,
  envs.db.password,
19
  {
20
    host: envs.db.host,
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
    dialect: "postgres",
  }
);

// db 객체에 값 입력
db.sequelize = sequelize;

// model들 생성
db.Doe = Doe;
Doe.init(sequelize);

db.Sgg = Sgg;
Sgg.init(sequelize);

db.Emd = Emd;
Emd.init(sequelize);

db.User = User;
User.init(sequelize);

41
42
db.Weather_In = Weather_In;
Weather_In.init(sequelize);
43

44
45
46
47
48
db.Weather_Out = Weather_Out;
Weather_Out.init(sequelize);

db.Data_Processing = Data_Processing;
Data_Processing.init(sequelize);
49
50
51
52
53
54

// model들 간에 Association 생성
Doe.associate(db);
Sgg.associate(db);
Emd.associate(db);
User.associate(db);
55
56
57
Weather_In.associate(db);
Weather_Out.associate(db);
Data_Processing.associate(db);
58
59
60

// Messages for Data Base.
const msg = {
61
  connection_success: "DB Connection Success.",
62
63
64
65
66
67
68
69
  connection_err: "DB Connection Error.",
  query_success: "DB Query Success.",
  query_err: "DB Querry Error.",
};

db.msg = msg;

export default db;