I'm looping through an array in node JS to update MYSQL database but the array starts at 0 and my auto incrementing database starts at 1. This obviusly offsets my whole data base by 1 row. Would much appreciate a solution to this. I'm using the sequelize NPM package aswell. Thanks in advance.
function ejsoutput(json){
for(var i = 0; i < 10;i++){
const updatedRank = json.entries[i].rank;
const updatedRating = json.entries[i].rating;
const updatedName = json.entries[i].character.name;
const updatedRealm = json.entries[i].character.realm.slug;
const updatedFaction = json.entries[i].faction.type;
const updatedPlayed = json.entries[i].season_match_statistics.played;
const updatedWon = json.entries[i].season_match_statistics.won;
const updatedLost = json.entries[i].season_match_statistics.lost;
Product.findByPk(i)
.then(product => {
product.rank = updatedRank;
product.rating = updatedRating;
product.name = updatedName;
product.realm = updatedRealm;
product.faction = updatedFaction;
product.played = updatedPlayed;
product.won = updatedWon;
product.lost = updatedLost;
return product.save();
})
.then(result => {
console.log('UPDATED PRODUCT')
})
.catch(err => console.log(err));
I just added this to the code.
Product.findByPk(i + 1)