I'm pulling data from an api and storing into the database, here is the values I fetched from api:
const optAdThisMonthsResult = [
[ 'google.com', 'Display', '2021-02-01', 3, 48, 76 ],
[ 'google.com', 'a1.php', '2021-02-01', 94, 31, 42 ],
]
After fetching I'm storing it in my database:
for (const data of optAdThisMonthsResult) {
//1. Assign values to store
let rowData = {
url: data[0],
tags: data[1],
date: data[2],
value1: data[3],
value2:data[4],
value3: data[5],
};
//2. Store to database
let ret = await OptAd.query().insert(rowData);
console.log(
`Inserted OptAd data with return code: ${require("util").inspect(ret)}`
);
}
Every time I run this script it also stores the duplicate values which are already present in the database, how can I build a test for this if the data is already present don't insert and only update this value1
value2
value3