【问题标题】:typeorm QueryBuilder: how to match column value of boolean?typeorm QueryBuilder:如何匹配布尔值的列值?
【发布时间】:2022-08-03 01:18:18
【问题描述】:

在 Typeorm 查询生成器中,当我想匹配其值等于布尔值 True 的行时,语法是什么?

例如,我有这个工作代码:

  await getConnection()
      .createQueryBuilder()
      .delete()
      .from(Notification)
      .where(\"id = :id\", { id: 1 })
      .andWhere(\'dstOrgId = :dstOrgId\', { dstOrgId: 1001 })
      .execute();

但是,如果我想匹配clicked 列的值为布尔值True 的所有行,我应该怎么写呢?

我想做类似的事情:

  await getConnection()
      .createQueryBuilder()
      .delete()
      .from(Notification)
      .where(\"clicked = :x\", { x: true })
      .andWhere(\"viewed = :x\", { x: false })
      .execute();

但是上面的代码似乎不是很好的语法,或者“正确”的语法

    标签: typescript typeorm


    【解决方案1】:

    这应该对所有人都有帮助

    需要使用@Column 属性“变压器”

    此建议已被 typeorm 团队分享

    https://github.com/typeorm/typeorm/issues/3875 https://github.com/typeorm/typeorm/issues/3942

    【讨论】:

      猜你喜欢
      • 2021-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多