locationSetting.js 2.92 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import fs from "fs";
// import mysql from "mysql";
import Sequelize from "sequelize";
import dotenv from "dotenv";

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

const sequelize = new Sequelize(
  envs.DB_DATABASE,
  envs.DB_USER,
  envs.DB_PASSWORD,
  {
    host: envs.DB_HOST,
    dialect: "postgres",
  }
);

const checkCONN = async () => {
  try {
    await sequelize.authenticate();
    console.log("Connection has been established successfully.");
    sequelize.close();
  } catch (error) {
    console.error("Unable to connect to the database:", error);
  }
};

checkCONN();
// // DB Connection
// const db = mysql.createConnection({
//   host: process.env.MYSQL_HOST || "localhost",
//   user: process.env.MYSQL_USER || "root",
//   password: process.env.MYSQL_PASSWORD,
//   database: process.env.MYSQL_DATABASE || "EUE",
// });

// const inputDo = (code, name) => {
//   name = name.replace(/\s/g, "");
//   let q = `INSERT INTO LOCDO (CODE,DONAME) VALUES (${code},'${name}');`;
//   db.query(q, (err, result) => {
//     if (err) {
//       console.log(err);
//       return;
//     }
//     console.log("Result : " + result);
//   });
// };

// const inputSi = (code, name, doCode) => {
//   name = name.replace(/\s/g, "");
//   let q = `INSERT INTO LOCSIGUNGU (CODE,DOCODE,SGGNAME) VALUES (${code},${doCode},'${name}');`;
//   db.query(q, (err, result) => {
//     if (err) {
//       console.log(err);
//       return;
//     }
//     console.log("Result : " + result);
//   });
// };

// const inputDong = (code, name, doCode, siCode) => {
//   name = name.replace(/\s/g, "");
//   let q = `INSERT INTO LOCINFO (CODE,DOCODE,SGGCODE,EMDNAME) VALUES (${code},${doCode},${siCode},'${name}');`;
//   db.query(q, (err, result) => {
//     if (err) {
//       console.log(err);
//       return;
//     }
//     console.log("Result : " + result);
//   });
// };

// const setDB = () => {
//   // DB Connect
//   db.connect((err) => {
//     if (err) {
//       console.log(err);
//       return;
//     }
//     console.log("connected as id" + db.threadId);
//   });

//   // File Read
//   let originData = fs.readFileSync("data/admAddressCode.csv", "utf8");

//   // Separate Data & Input Data
//   let sepData = originData.split("\r\n");
//   let setDoCode = new Set();
//   let setSiCode = new Set();

//   sepData.forEach((line) => {
//     line = line.replace(/\s/g, "");
//     let addr = line.split(",");

//     const doCode = Number(addr[0]);
//     if (!setDoCode.has(doCode)) {
//       const doName = addr[1];
//       inputDo(doCode, doName);
//       setDoCode.add(doCode);
//     }

//     const siCode = Number(addr[2]);
//     if (!setSiCode.has(siCode)) {
//       const siName = addr[3];
//       inputSi(siCode, siName, doCode);
//       setSiCode.add(siCode);
//     }

//     const dongCode = Number(addr[4]);
//     const dongName = addr[5];
//     inputDong(dongCode, dongName, doCode, siCode);
//   });

//   // Connection Close
//   db.end();
// };

// setDB();