首页 > 解决方案 > 回滚后的 Mikroorm id 漏洞

问题描述

我将几个实体保存到我的数据库中:

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

当其中一个失败时,事务失败并回滚。假设这些任务是他们失败的前 4 个任务,数据库中没有任务,但是下次我插入一个任务时,它从 id 5 开始。有没有办法从持久的 id 中删除这些任务?

我也在设置RequestContext:

app.use((_req, _res, next) => {
    RequestContext.create(orm.em, next);
});

标签: node.jsmikro-orm

解决方案


推荐阅读