postgresql - TypeORM 查询生成器查找 id 等于 PostgreSQL UUID 的位置

标签 postgresql nestjs uuid typeorm query-builder

我有一个带有@PrimaryGeneeratedColumn('uuid')的表。 当我尝试使用 TypeORM 查询生成器查询它时,出现错误

QueryFailedError: invalid input syntax for type uuid: "{"id":"8f294654-8385-4579-a714-0fae73839430"}"

查询是

this.repository.createQueryBuilder('products')
  .leftJoinAndSelect('products.brand', 'brands')
  .leftJoinAndSelect('products.category', 'categories')
  .leftJoinAndSelect('products.productOptions', 'productOptions')
  .where('products.id = :id', { id })
  .getOne()

有没有办法将字符串 uuid 转换为 postgresql uuid?

最佳答案

看起来 id 正在期待 "8f294654-8385-4579-a714-0fae73839430" 但不知何故你传递了 {"id":"的对象8f294654-8385-4579-a714-0fae73839430"}

关于postgresql - TypeORM 查询生成器查找 id 等于 PostgreSQL UUID 的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68047134/

相关文章:

datetime - 如何使用 postgres 将时间间隔转换为小时数?

rxjs - 迁移到新版本后,NestJS 上的 forkJoin 不起作用

javascript - 如何修复套接字 io 中的 400 错误错误请求?

typescript - 使用代码优先方法在 Nestjs 中创建突变

go - 如何以特定模式生成 UUID

java - HashMap UUID 或 String 作为键?

postgresql - 从标准输入复制在 liquibase 中不起作用

java - 无法为我的实体生成 UUID ID

python - 返回十六进制 UUID 作为 Django 模型字符字段的默认值

mysql - 如何将尽可能多的值插入到另一个表中,因为它是在其他表的特定列中定义的