微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

GraphQL 中 Postgres 的数组重叠 (&&) 函数的等价物是什么?

如何解决GraphQL 中 Postgres 的数组重叠 (&&) 函数的等价物是什么?

在 Postgres 中,数组的 overlap ("&&") operator 用于检查两个数组是否有任何共同元素。

例如

查询 结果
数组[1,4,3]&&数组[2,1] 真实
数组[1,5]

GraphQL 中是否有类似的东西?

另外,有什么我可以在 Hasura 中使用的吗?


  • 我能想到的一个更具体的实际用例如下。 (我只是为了澄清而编写它们,并没有运行或验证语法。)
// Assume a you want to find all restaurants with any of the selected cuisines.

const restaurantA = {...,cuisineType: ['Fusion','Chinese','Japanese','Korean']}
const restaurantB = {...,cuisineType: ['vegetarian','Thai']}
const restaurantC = {...,cuisineType: ['European']}

// Assume the data above is stored in Postgres (as an array in column field,not using a bridge table.

const sql_1 = "SELECT * 
               FROM restaurants 
               WHERE cuisine_type && ['Korean','Japanese']" // Expect restaurantA and restaurantC
const sql_2 = "SELECT * 
               FROM restaurants 
               WHERE cuisine_type && ['vegetarian','European']" // Expect restaurantB and restaurantC

### GOAL: I want to use GraphQL,Apollo,Hasura to have the same effect as sql_1 and sql_2

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。