Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
I
import-excel-to-postgresql
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Bovorn Siriampairat
import-excel-to-postgresql
Commits
b1d40966
Commit
b1d40966
authored
Jul 18, 2023
by
bovornsiriampairat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added Console Log for Execution
parent
39ad325f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
3 deletions
+21
-3
import_multi_row.js
import_multi_row.js
+19
-1
output.json
output.json
+2
-2
pr_pay.xlsx
pr_pay.xlsx
+0
-0
No files found.
import_multi_row.js
View file @
b1d40966
...
...
@@ -55,6 +55,11 @@ xml2js.parseString(xmlString, async (err, result) => {
employee
:
[],
};
let
skippedRecords
=
0
;
let
importedRecords
=
0
;
const
startTime
=
new
Date
();
for
(
let
i
=
1
;
i
<
data
.
length
;
i
++
)
{
const
row
=
data
[
i
];
const
mappedEmployee
=
{};
...
...
@@ -80,6 +85,10 @@ xml2js.parseString(xmlString, async (err, result) => {
},
[]);
jsonData
.
employee
.
push
(
mappedEmployee
);
// Calculate progress
const
progress
=
(
i
/
(
data
.
length
-
1
))
*
100
;
console
.
log
(
`Progress:
${
progress
.
toFixed
(
2
)}
%`
);
}
try
{
...
...
@@ -99,9 +108,10 @@ xml2js.parseString(xmlString, async (err, result) => {
try
{
await
client
.
query
(
query
,
values
);
console
.
log
(
'Data inserted successfully.'
)
;
importedRecords
++
;
}
catch
(
err
)
{
console
.
error
(
'Error inserting data:'
,
err
);
skippedRecords
++
;
// Add retry logic or handle the error accordingly
}
}
...
...
@@ -109,12 +119,20 @@ xml2js.parseString(xmlString, async (err, result) => {
client
.
release
();
// Release the client back to the pool
const
endTime
=
new
Date
();
const
executionTime
=
(
endTime
-
startTime
)
/
1000
;
// Convert JSON to string
const
jsonString
=
JSON
.
stringify
(
jsonData
,
null
,
2
);
// Write JSON to file
fs
.
writeFileSync
(
outputFilename
,
jsonString
);
console
.
log
(
`Data processed successfully.`
);
console
.
log
(
`Total records:
${
data
.
length
-
1
}
`
);
console
.
log
(
`Skipped records:
${
skippedRecords
}
`
);
console
.
log
(
`Imported records:
${
importedRecords
}
`
);
console
.
log
(
`Execution time:
${
executionTime
.
toFixed
(
2
)}
seconds`
);
console
.
log
(
`Conversion completed. Output JSON file created:
${
outputFilename
}
`
);
}
catch
(
err
)
{
console
.
error
(
'Error connecting to the database:'
,
err
);
...
...
output.json
View file @
b1d40966
...
...
@@ -6,12 +6,12 @@
{
"tagType"
:
"INC"
,
"formulaid"
:
"INC1"
,
"value"
:
"
5
0000"
"value"
:
"
6
0000"
},
{
"tagType"
:
"INC"
,
"formulaid"
:
"INC2"
,
"value"
:
"0"
"value"
:
"
2000
0"
},
{
"tagType"
:
"INC"
,
...
...
pr_pay.xlsx
View file @
b1d40966
No preview for this file type
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