Commit e1ef3ad6 by bovornsiriampairat

Added Truncate Function

parent b1d40966
......@@ -60,6 +60,17 @@ xml2js.parseString(xmlString, async (err, result) => {
const startTime = new Date();
try {
// Connect to the PostgreSQL database
const client = await pool.connect();
const tableName = 'tpytran1'; // Specify the table name
// Truncate the table and restart identity
const truncateQuery = `TRUNCATE TABLE ${tableName} RESTART IDENTITY`;
await client.query(truncateQuery);
// Insert the data into the PostgreSQL database
for (let i = 1; i < data.length; i++) {
const row = data[i];
const mappedEmployee = {};
......@@ -91,12 +102,6 @@ xml2js.parseString(xmlString, async (err, result) => {
console.log(`Progress: ${progress.toFixed(2)}%`);
}
try {
// Connect to the PostgreSQL database
const client = await pool.connect();
// Insert the data into the PostgreSQL database
const tableName = 'tpytran1'; // Specify the table name
for (const employee of jsonData.employee) {
const { employeeid, formulaid } = employee;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment