javascript - 在 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
有什么解决办法吗?
解决方案
您可以简单地使用它来避免 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。
推荐阅读
- amazon-web-services - aws - 获取 AWS CodePipeline 的失败部署计数
- jquery - 当一个项目可见时如何隐藏其他项目?
- sql - 具有来自另一列的自引用 ID 的 SQL UPDATE 列
- dns - 将一个本地 url 重定向到任意 url 以方便本地开发。Windows主机文件?
- javascript - 动态网格线计算
- express - 如何从制表符操作链接更新数据库
- c# - 如何使用 EFCore 获取一个表的主键计数到另一个表
- c# - 我们可以在没有 Microsoft 身份平台的情况下在 .net core 5 中实施 azure AD 吗?
- c# - 为什么 WPF 文本框 DesiredHeight 过早地为新行提供空间?
- javascript - Next.js i18n 动态链接与 /lang/slug/[id] 得到错误 404