【问题标题】:TypeORM delete using WHERE with OR operator using RepositoryTypeORM delete using WHERE with OR operator using Repository
【发布时间】:2021-05-28 01:05:08
【问题描述】:

我有一个Repository 类,我想根据OR 运算符组合的两个条件使用继承方法repository.delete() 删除我的数据库中的实体。

我想实现这样的目标:

deleteAllAboOfUser(userId: string): Promise<DeleteResult> {
        return this.delete([
            { followerId: userId},
            {followingId: userId}
        ]);
    }

生成的 SQL 应该如下所示:

DELETE FROM subscription WHERE follower_id = 'xxxx' OR following_id = 'xxxx';

但目前似乎不可能使用OR 条件进行删除,而只能使用AND

【问题讨论】:

  • 可以使用OR。你能添加你的delete 方法吗?

标签: mysql node.js sequelize.js nestjs typeorm


【解决方案1】:

检查了一个仓库API的documentation,发现没有基于OR操作符的规定要删除。

我认为您需要使用查询生成器来实现这一点。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-14
    • 2022-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-18
    相关资源
    最近更新 更多