首页 > 解决方案 > 在 uuid 中转义连字符(-)以检查数据库中的值

问题描述

我有一个查询,它使用 UUID 检查数据库中的值。现在问题出-在 UUID 之间。

我正在做类似的事情

async getRecurringOrderCount(orderId: string) {
        return await this.createQueryBuilder()
            .where("parent_id = :orderId", {orderId})
            .andWhere("order_status_id = \'bd8c82ee-a9ae-48a6-b4c2-23ca0d39f55c\'") // this will  check inclusive of '' which will never get me a result
            //.orWhere("order_status_id = \'949438ca-fb6a-48bb-be2c-6a181cf5a9e1\'")
            .getCount()
    }

在我的数据库中,我将值存储为这样的字符串bd8c82ee-a9ae-48a6-b4c2-23ca0d39f55c

有什么解决办法吗?

标签: javascriptpostgresqluuidtypeorm

解决方案


您可以简单地使用它来避免 typeorm 使用您的 ''。

async getRecurringOrderCount(orderId: string) {
    return await this.createQueryBuilder()
        .where("parent_id = :orderId", {orderId})
        .andWhere("order_status_id = :orderStatusId", {orderStatusId:'bd8c82ee-a9ae-48a6-b4c2-23ca0d39f55c'})
        .getCount()
}

它将用提供的值替换 orderStatusId。


推荐阅读