typeorm postgres 选择其中 json 字段等于某个值的位置 [英] typeorm postgres select where json field equals some value
本文介绍了typeorm postgres 选择其中 json 字段等于某个值的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
目标:编写一个选择查询,返回 state 等于florida"的所有行.
Goal: write a select query that returns all rows where state equals "florida".
实体列:
@Column({ type: 'json'})
public address: Address;
示例列值:
{"city": "miami", "state": "florida"}
示例查询(不起作用):
Example query (doesn't work):
getManager().getRepository(User)
.createQueryBuilder('user')
.select()
.where('user.address.state =:state', {state: "florida"})
typeorm 目前是否支持此功能?如果是这样,我需要如何修改 where 子句以返回正确的行?
Is this functionality currently supported in typeorm? If so, how would I need to modify my where clause to return the correct rows?
推荐答案
搞定了.
正确的语法:
.where(`user.address ::jsonb @> \'{"state":"${query.location}"}\'`)
这篇关于typeorm postgres 选择其中 json 字段等于某个值的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文