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 @@
"express"
:
"^4.17.1"
,
"helmet"
:
"^4.1.1"
,
"morgan"
:
"^1.10.0"
,
"mysql"
:
"^2.
18.1
"
,
"mysql
2
"
:
"^2.
2.5
"
,
"node-fetch"
:
"^2.6.1"
,
"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
"
;
// 각각의 지역 코드 정보를 가져오는
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
)
=>
{
const
query
=
"
SELECT CODE, DONAME FROM LOCDO
"
;
db
((
connErr
,
connection
)
=>
{
if
(
connErr
)
{
console
.
log
(
dbMSG
.
connection_err
);
res
.
status
(
statusCode
.
err
).
json
({
error
:
serverMSG
.
server_err
});
}
else
{
connection
.
query
(
query
,
(
queryErr
,
result
)
=>
{
if
(
queryErr
)
{
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
();
}
});
const
[
isError
,
result
]
=
await
getQueryResult
(
query
);
if
(
!
isError
)
{
res
.
status
(
statusCode
.
ok
).
json
({
DO
:
result
});
}
else
{
console
.
log
(
result
);
res
.
status
(
statusCode
.
err
).
send
(
serverMSG
.
server_err
);
}
};
export
const
getSGG
=
(
req
,
res
)
=>
{
// SGG Code에 대한 GET 요청 처리
export
const
getSGG
=
async
(
req
,
res
)
=>
{
const
{
params
:
{
id
},
}
=
req
;
const
query
=
`SELECT CODE, SGGNAME FROM LOCSIGUNGU WHERE DOCODE =
${
id
}
`
;
db
((
connErr
,
connection
)
=>
{
if
(
connErr
)
{
console
.
log
(
dbMSG
.
connection_err
);
res
.
status
(
statusCode
.
err
).
json
({
error
:
serverMSG
.
server_err
});
}
else
{
connection
.
query
(
query
,
(
queryErr
,
result
)
=>
{
if
(
queryErr
)
{
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
();
}
});
const
[
isError
,
result
]
=
await
getQueryResult
(
query
);
if
(
!
isError
)
{
res
.
status
(
statusCode
.
ok
).
json
({
DO
:
id
,
SGG
:
result
});
}
else
{
console
.
log
(
result
);
res
.
status
(
statusCode
.
err
).
send
(
serverMSG
.
server_err
);
}
};
export
const
getEMD
=
(
req
,
res
)
=>
{
// EMD Code에 대한 GET 요청 처리
export
const
getEMD
=
async
(
req
,
res
)
=>
{
const
{
params
:
{
id
},
}
=
req
;
const
query
=
`SELECT CODE, EMDNAME FROM LOCINFO WHERE SGGCODE =
${
id
}
`
;
db
((
connErr
,
connection
)
=>
{
if
(
connErr
)
{
console
.
log
(
dbMSG
.
connection_err
);
res
.
status
(
statusCode
.
err
).
json
({
error
:
serverMSG
.
server_err
});
}
else
{
connection
.
query
(
query
,
(
queryErr
,
result
)
=>
{
if
(
queryErr
)
{
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
();
}
});
const
[
isError
,
result
]
=
await
getQueryResult
(
query
);
if
(
!
isError
)
{
res
.
status
(
statusCode
.
ok
).
json
({
SGG
:
id
,
EMD
:
result
});
}
else
{
console
.
log
(
result
);
res
.
status
(
statusCode
.
err
).
send
(
serverMSG
.
server_err
);
}
};
server/src/db.js
View file @
4928599e
import
mysql
from
"
mysql
"
;
import
mysql
from
"
mysql
2/promise
"
;
import
dotenv
from
"
dotenv
"
;
dotenv
.
config
();
...
...
@@ -12,20 +12,12 @@ const db_config = {
connectionLimit
:
5
,
};
// Creation of MySQL Pool
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
);
});
};
// Creation of MySQL Pool, and Export
export
const
pool
=
mysql
.
createPool
(
db_config
);
// Messages for Data Base.
export
const
dbMSG
=
{
connection_err
:
"
DB Connection Error.
"
,
query_
err
:
"
DB Query
Error
.
"
,
query_
success
:
"
Query
Success
"
,
query_
success
:
"
DB 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