【问题标题】:TypeORM-NestJs Join on Json columnTypeORM-NestJs 加入 Json 列
【发布时间】:2021-08-28 03:57:30
【问题描述】:

使用 typeorm-NestJs 连接两个 mysql 表 其中table 1(t1) 是普通表 & table 2(t2) 有一列包含 JSON 数据

现在我需要根据t1.id == t2.column_name.id加入他们

但我在该查询中遇到错误

我正在使用的查询:-

const results  = await this.connection.createQueryBuilder(ABCEntity,'t1')
    .innerJoinAndMapMany('t1.Id',xyzEntity,'t2','t1.Id = t2.column_name.$.Id')
    .where('t1.Id = :Id',{Id: id})
    .getMany()
    .catch(err => console.log(err));

我得到的错误:-

code: 'ER_PARSE_ERROR',
  errno: 1064,
  sqlMessage: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.Id WHERE `t1`.`Id` = 'b6D812aF-9e22-4a5a-a292-6rc5021bfv0a'' at line 1",
  sqlState: '42000',

【问题讨论】:

  • t2.column_name.$.Id 不正确,试试t2.column_name->'$.Id'

标签: mysql typescript inner-join nestjs typeorm


【解决方案1】:

对我有用的是,一切都用反引号 例如:`t1.Id = t2.column_name->'$.Id'

const results  = await this.connection.createQueryBuilder(ABCEntity,'t1')
.innerJoinAndMapMany('t1.Id',xyzEntity,'t2',`t1.Id = t2.column_name->'$.Id'`)
.where('t1.Id = :Id',{Id: id})
.getMany()
.catch(err => console.log(err));

【讨论】:

    猜你喜欢
    • 2022-08-18
    • 2021-05-27
    • 1970-01-01
    • 2021-07-21
    • 2020-12-09
    • 2021-08-04
    • 2020-09-01
    • 2022-09-24
    • 2021-04-23
    相关资源
    最近更新 更多