【问题标题】:TypeORM update query using repository pattern, how to update a table with a where clause selection and update only one field使用存储库模式的 TypeORM 更新查询,如何使用 where 子句选择更新表并仅更新一个字段
【发布时间】:2021-11-12 11:47:25
【问题描述】:

我有一个带有is_active 字段的条形码表。当用户想要停用此条形码时,我想更新此布尔字段。

在条码实体中,称为isActive

我尝试使用存储库模式进行此查询,但它提供了以下 SQL 查询。

this.barcodeRepository
      .createQueryBuilder()
      .update(Barcode)
      .set({ isActive: true })
      .where('code = :codeToupdate', { codeToupdate: 'sfsdfdsf' })
      .getQuery();

输出的 SQL 查询是这样的。

UPDATE "barcode" SET "is_active" = :orm_param_0 WHERE "code" = :codeToupdate

我不确定是什么导致它输出:orm_param_0

请任何人帮助正确的 typeorm 更新步骤..

【问题讨论】:

    标签: postgresql nestjs typeorm


    【解决方案1】:

    试试这个:

    this.barcodeRepository
          .createQueryBuilder()
          .update({ isActive: true })
          .where('code = :codeToupdate', { codeToupdate: 'sfsdfdsf' })
          .getQuery();
    

    【讨论】:

      猜你喜欢
      • 2023-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-29
      • 2020-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多