如何输入或更新列值

问题描述 投票:0回答:1
UPDATE 'table' 
SET 'Column' = 'Column' - 30 
WHERE 'ID' = 1;
async update(ID: number, value: number) {
    await this.Repository.update({ID}, { ? ? ?})
}

我可以知道如何使用上面的 SQL 吗?

我应该使用 typeorm 查询生成器吗?

请帮助我

typeorm
1个回答
0
投票

尝试这样:

解决方案1:

const isEntityFound = await this.repository.findOne(ID);
const decrement: number = 30
  if (isEntityFound) {
        isEntityFound.Column -= decrement;
        await this.repository.save(isEntityFound);
  }

解决方案2:

async update(ID: number) {
    const decrement: number = 30
    await this.Repository.createQueryBuilder()
        .update(table)
        .set({ Column: () => `Column - ${decrement}` })
        .where("ID = :idParam", { idParam: ID })
        .execute();
}
© www.soinside.com 2019 - 2024. All rights reserved.