【发布时间】: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