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
01d96550
Commit
01d96550
authored
Mar 26, 2021
by
KangMin An
Browse files
DB Setting - MySQL 이용 지역구 정보입력(해당파일 독립실행).
parent
b95f0498
Changes
2
Show whitespace changes
Inline
Side-by-side
server/package.json
View file @
01d96550
...
...
@@ -26,6 +26,7 @@
"express"
:
"^4.17.1"
,
"helmet"
:
"^4.1.1"
,
"morgan"
:
"^1.10.0"
,
"mysql"
:
"^2.18.1"
,
"node-fetch"
:
"^2.6.1"
,
"pug"
:
"^3.0.0"
},
...
...
server/src/db/dbsetting.js
0 → 100644
View file @
01d96550
import
fs
from
"
fs
"
;
import
mysql
from
"
mysql
"
;
import
dotenv
from
"
dotenv
"
;
dotenv
.
config
();
// 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
();
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