小编Bey*_*Sea的帖子

TypeORM upsert - 如果不存在则创建

TypeORM是否包含一些功能以避免这种情况:

let contraption = await thingRepository.findOne({ name : "Contraption" });

if(!contraption) // Create if not exist
{
    let newThing = new Thing();
    newThing.name = "Contraption"
    await thingRepository.save(newThing);
    contraption = newThing;
}
Run Code Online (Sandbox Code Playgroud)

就像是 :

let contraption = await thingRepository.upsert({ name : "Contraption" });
Run Code Online (Sandbox Code Playgroud)

typescript typeorm

7
推荐指数
8
解决办法
1万
查看次数

标签 统计

typeorm ×1

typescript ×1