I have to import rows from a .csv
, and put them in my database (chunks of 500). To do this i'm using the sequelize bulkCreate
functionality.
I have a field called address
which is required (not nullable). If one of the rows fails to insert (because the row in my csv doesn't have an address) the entire batch fails. what I want to achieve is that bulkCreate
attempts to insert the lines, and ignores the ones which fail.
Anyway to achieve this? Here's my current code if it helps
export const createEnterprise = async (rows: any[]) => {
try {
// Create enterprise record
await models.enterprise.bulkCreate(rows);
} catch (err) {
console.log(err);
throw err
}
};