Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
students
eue
Commits
4928599e
Commit
4928599e
authored
May 16, 2021
by
KangMin An
Browse files
Update : MySQL 비동기 처리 코드 갱신 및 기타 코드 갱신
parent
d0ccf743
Changes
3
Hide whitespace changes
Inline
Side-by-side
server/package.json
View file @
4928599e
...
@@ -26,7 +26,7 @@
...
@@ -26,7 +26,7 @@
"express"
:
"^4.17.1"
,
"express"
:
"^4.17.1"
,
"helmet"
:
"^4.1.1"
,
"helmet"
:
"^4.1.1"
,
"morgan"
:
"^1.10.0"
,
"morgan"
:
"^1.10.0"
,
"mysql"
:
"^2.
18.1
"
,
"mysql
2
"
:
"^2.
2.5
"
,
"node-fetch"
:
"^2.6.1"
,
"node-fetch"
:
"^2.6.1"
,
"pug"
:
"^3.0.0"
"pug"
:
"^3.0.0"
},
},
...
...
server/src/controllers/locCodeController.js
View file @
4928599e
import
{
getPoolConnection
as
db
,
dbMSG
}
from
"
../db
"
;
import
{
pool
as
db
,
dbMSG
}
from
"
../db
"
;
import
{
serverMSG
,
statusCode
}
from
"
../serverinfo
"
;
import
{
serverMSG
,
statusCode
}
from
"
../serverinfo
"
;
// 각각의 지역 코드 정보를 가져오는
const
getQueryResult
=
async
(
query
)
=>
{
let
isError
=
false
;
let
result
;
try
{
const
[
row
,
fields
]
=
await
db
.
execute
(
query
);
result
=
row
;
console
.
log
(
dbMSG
.
query_success
);
}
catch
(
error
)
{
//Error Log
console
.
log
(
""
,
error
);
isError
=
true
;
// 발생한 오류가 DB와 연결 오류인지 확인 후 Error Message 지정 및 전달
if
(
error
.
code
===
"
ECONNREFUSED
"
)
result
=
dbMSG
.
connection_err
;
else
result
=
dbMSG
.
query_err
;
}
return
[
isError
,
result
];
};
// Do Code에 대한 GET 요청 처리
export
const
getDo
=
async
(
req
,
res
)
=>
{
export
const
getDo
=
async
(
req
,
res
)
=>
{
const
query
=
"
SELECT CODE, DONAME FROM LOCDO
"
;
const
query
=
"
SELECT CODE, DONAME FROM LOCDO
"
;
db
((
connErr
,
connection
)
=>
{
const
[
isError
,
result
]
=
await
getQueryResult
(
query
);
if
(
connErr
)
{
console
.
log
(
dbMSG
.
connection_err
);
if
(
!
isError
)
{
res
.
status
(
statusCode
.
err
).
json
({
error
:
serverMSG
.
server_err
});
res
.
status
(
statusCode
.
ok
).
json
({
DO
:
result
});
}
else
{
}
else
{
connection
.
query
(
query
,
(
queryErr
,
result
)
=>
{
console
.
log
(
result
);
if
(
queryErr
)
{
res
.
status
(
statusCode
.
err
).
send
(
serverMSG
.
server_err
);
console
.
log
(
dbMSG
.
query_err
);
}
res
.
status
(
statusCode
.
err
).
json
({
error
:
serverMSG
.
server_err
});
}
else
{
console
.
log
(
dbMSG
.
query_success
);
res
.
status
(
statusCode
.
ok
).
json
({
info
:
result
});
}
});
connection
.
release
();
}
});
};
};
export
const
getSGG
=
(
req
,
res
)
=>
{
// SGG Code에 대한 GET 요청 처리
export
const
getSGG
=
async
(
req
,
res
)
=>
{
const
{
const
{
params
:
{
id
},
params
:
{
id
},
}
=
req
;
}
=
req
;
const
query
=
`SELECT CODE, SGGNAME FROM LOCSIGUNGU WHERE DOCODE =
${
id
}
`
;
const
query
=
`SELECT CODE, SGGNAME FROM LOCSIGUNGU WHERE DOCODE =
${
id
}
`
;
db
((
connErr
,
connection
)
=>
{
const
[
isError
,
result
]
=
await
getQueryResult
(
query
);
if
(
connErr
)
{
console
.
log
(
dbMSG
.
connection_err
);
if
(
!
isError
)
{
res
.
status
(
statusCode
.
err
).
json
({
error
:
serverMSG
.
server_err
});
res
.
status
(
statusCode
.
ok
).
json
({
DO
:
id
,
SGG
:
result
});
}
else
{
}
else
{
connection
.
query
(
query
,
(
queryErr
,
result
)
=>
{
console
.
log
(
result
);
if
(
queryErr
)
{
res
.
status
(
statusCode
.
err
).
send
(
serverMSG
.
server_err
);
console
.
log
(
dbMSG
.
query_err
);
}
res
.
status
(
statusCode
.
err
).
json
({
error
:
serverMSG
.
server_err
});
}
else
{
console
.
log
(
dbMSG
.
query_success
);
res
.
status
(
statusCode
.
ok
).
json
({
info
:
result
});
}
});
connection
.
release
();
}
});
};
};
export
const
getEMD
=
(
req
,
res
)
=>
{
// EMD Code에 대한 GET 요청 처리
export
const
getEMD
=
async
(
req
,
res
)
=>
{
const
{
const
{
params
:
{
id
},
params
:
{
id
},
}
=
req
;
}
=
req
;
const
query
=
`SELECT CODE, EMDNAME FROM LOCINFO WHERE SGGCODE =
${
id
}
`
;
const
query
=
`SELECT CODE, EMDNAME FROM LOCINFO WHERE SGGCODE =
${
id
}
`
;
db
((
connErr
,
connection
)
=>
{
const
[
isError
,
result
]
=
await
getQueryResult
(
query
);
if
(
connErr
)
{
console
.
log
(
dbMSG
.
connection_err
);
if
(
!
isError
)
{
res
.
status
(
statusCode
.
err
).
json
({
error
:
serverMSG
.
server_err
});
res
.
status
(
statusCode
.
ok
).
json
({
SGG
:
id
,
EMD
:
result
});
}
else
{
}
else
{
connection
.
query
(
query
,
(
queryErr
,
result
)
=>
{
console
.
log
(
result
);
if
(
queryErr
)
{
res
.
status
(
statusCode
.
err
).
send
(
serverMSG
.
server_err
);
console
.
log
(
dbMSG
.
query_err
);
}
res
.
status
(
statusCode
.
err
).
json
({
error
:
serverMSG
.
server_err
});
}
else
{
console
.
log
(
dbMSG
.
query_success
);
res
.
status
(
statusCode
.
ok
).
json
({
info
:
result
});
}
});
connection
.
release
();
}
});
};
};
server/src/db.js
View file @
4928599e
import
mysql
from
"
mysql
"
;
import
mysql
from
"
mysql
2/promise
"
;
import
dotenv
from
"
dotenv
"
;
import
dotenv
from
"
dotenv
"
;
dotenv
.
config
();
dotenv
.
config
();
...
@@ -12,20 +12,12 @@ const db_config = {
...
@@ -12,20 +12,12 @@ const db_config = {
connectionLimit
:
5
,
connectionLimit
:
5
,
};
};
// Creation of MySQL Pool
// Creation of MySQL Pool, and Export
const
pool
=
mysql
.
createPool
(
db_config
);
export
const
pool
=
mysql
.
createPool
(
db_config
);
// Pool을 이용시, Connection을 생성 후 반환하여 사용
export
const
getPoolConnection
=
(
callback
)
=>
{
console
.
log
(
"
db_connection()
"
);
pool
.
getConnection
(
async
(
err
,
connection
)
=>
{
console
.
log
(
"
db_connection_poolConnection()
"
);
await
callback
(
err
,
connection
);
});
};
// Messages for Data Base.
export
const
dbMSG
=
{
export
const
dbMSG
=
{
connection_err
:
"
DB Connection Error.
"
,
connection_err
:
"
DB Connection Error.
"
,
query_
err
:
"
DB Query
Error
.
"
,
query_
success
:
"
DB Query
Success
.
"
,
query_
success
:
"
Query
Success
"
,
query_
err
:
"
DB
Quer
r
y
Error.
"
,
};
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment