index.js 1.32 KB
Newer Older
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import Sequelize from "sequelize";
import dotenv from "dotenv";
import Doe from "../models/doe";
import Sgg from "../models/sgg";
import Emd from "../models/emd";
import User from "../models/user";
import Weather_in from "../models/weather_in";
import Weather_out from "../models/weather_out";

dotenv.config();
const envs = process.env;

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

// PostgreSQL과 연결된 Sequelize 객체 생성
const sequelize = new Sequelize(
  envs.DB_DATABASE,
  envs.DB_USER,
  envs.DB_PASSWORD,
  {
    host: envs.DB_HOST,
    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);

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

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

// model들 간에 Association 생성
Doe.associate(db);
Sgg.associate(db);
Emd.associate(db);
User.associate(db);
Weather_in.associate(db);
Weather_out.associate(db);

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

db.msg = msg;

export default db;