Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
IQB
PersonalDB
Commits
94c05307
Commit
94c05307
authored
Feb 10, 2022
by
mechtelm
Browse files
Add data import for staff
parent
32824402
Changes
2
Hide whitespace changes
Inline
Side-by-side
setup/database/insert_db_staff.js
0 → 100644
View file @
94c05307
const
{
Pool
}
=
require
(
'
pg
'
);
const
fs
=
require
(
'
fs
'
);
require
(
'
dotenv
'
).
config
({
path
:
'
./docker.env
'
});
const
staff_data
=
fs
.
readFileSync
(
'
staff_data.txt
'
).
toString
();
const
all_lines
=
staff_data
.
split
(
/
\n
/
);
const
pool
=
new
Pool
({
user
:
process
.
env
.
POSTGRES_USER
,
password
:
process
.
env
.
POSTGRES_PASSWORD
,
database
:
process
.
env
.
POSTGRES_DB
,
host
:
'
localhost
'
,
port
:
5432
,
max
:
all_lines
.
length
})
all_lines
.
forEach
(
line
=>
{
if
(
line
)
{
const
data
=
line
.
split
(
'
###
'
);
let
date_splits
=
data
[
4
].
split
(
'
.
'
);
const
start_date
=
"
Date('
"
+
date_splits
[
2
]
+
'
-
'
+
date_splits
[
1
]
+
'
-
'
+
date_splits
[
0
]
+
"
')
"
;
let
end_date
=
""
;
if
(
data
[
5
]
!==
'
unbefristet
'
)
{
date_splits
=
data
[
5
].
split
(
'
.
'
);
end_date
=
"
Date('
"
+
date_splits
[
2
]
+
'
-
'
+
date_splits
[
1
]
+
'
-
'
+
date_splits
[
0
]
+
"
')
"
;
}
if
(
end_date
)
{
const
valuesString
=
"
'
"
+
data
[
2
]
+
"
', '
"
+
data
[
3
]
+
"
', '
"
+
data
[
0
]
+
"
',
"
+
start_date
+
"
,
"
+
end_date
+
"
, '
"
+
data
[
1
]
+
"
'
"
;
const
sql
=
'
INSERT INTO public.staff (name, surname, contract_type, contract_start, contract_end, cms_id) VALUES (
'
+
valuesString
+
'
);
'
;
pool
.
query
(
sql
,
function
(
err
,
result
){
console
.
log
(
err
,
result
);
});
}
else
{
console
.
log
(
'
###
'
);
const
valuesString
=
"
'
"
+
data
[
2
]
+
"
', '
"
+
data
[
3
]
+
"
', '
"
+
data
[
0
]
+
"
',
"
+
start_date
+
"
, '
"
+
data
[
1
]
+
"
'
"
;
const
sql
=
'
INSERT INTO public.staff (name, surname, contract_type, contract_start, cms_id) VALUES (
'
+
valuesString
+
'
);
'
;
pool
.
query
(
sql
,
function
(
err
,
result
){
console
.
log
(
err
,
result
);
});
}
}
});
pool
.
end
()
setup/database/staff_data.txt
0 → 100644
View file @
94c05307
IQB-Vertrag###9648000363###Yung###Phong###01.11.2015###30.04.2024
IQB-Vertrag###9648000564###Schneider###Wolfgang###01.01.2014###unbefristet
Write
Preview
Supports
Markdown
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