TypeORM-NestJs 在 Json 列加入
TypeORM-NestJs Join on Json column
加入两个 mysql table 使用 typeorm-NestJs
其中 table 1(t1)
是正常的 table
& 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',
对我有用的是,反引号中的所有内容
例如:`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));
加入两个 mysql table 使用 typeorm-NestJs
其中 table 1(t1)
是正常的 table
& 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',
对我有用的是,反引号中的所有内容 例如:`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));