0

I am saving several entities to my database:

const tasks = taskInputs.map(task => {
    this.repo.create({
        name,
        state, 
    });
})
    
try{
    await this.repo.persist(tasks).flush();
}catch(err){
    ...
}

When one of them fail transaction fail and it rolls back. Lets say that those tasks were the first 4 tasks they fail no tasks are in the database, but next time I insert a task it starts from id 5. Is there a way to remove those tasks from the persisted ids?

I am also setting RequestContext:

app.use((_req, _res, next) => {
    RequestContext.create(orm.em, next);
});
ivaylo
  • 791
  • 1
  • 8
  • 23
  • This question has nothing to do with ORMs or node.js, so that is why you havent received any asnwers I guess. This is how autoincrement columns work, you can reset the count, but it sounds like a very bad idea to do it from code based on rollbacks. e.g. for mysql you can do this https://stackoverflow.com/questions/8923114/how-to-reset-auto-increment-in-mysql (other platforms support this too, e.g. postgres have sequences you can reset) – Martin Adámek Aug 04 '21 at 12:09

0 Answers0