Ale*_*ada 3 gql graphql react-apollo hasura
在我的 hasura.io 数据库中,我有一个booking
表,我在其中存储具有以下属性的预订:
现在,从 UI 中,当用户进行预订时,我想检查之前是否有任何涉及这些日期范围的预订。
例如。用户想要在以下日期进行预订:
{
"from": "2020-03-31T14:00:00+00:00",
"to": "2020-03-31T17:00:00+00:00"
}
Run Code Online (Sandbox Code Playgroud)
但在同一天有一个预订:
{
"from": "2020-03-31T15:00:00+00:00",
"to": "2020-04-01T17:00:00+00:00"
}
Run Code Online (Sandbox Code Playgroud)
请注意,此预订不是在用户尝试预订的日期范围内进行的。因此,以下查询将不返回任何内容。
query CheckBooking($from: timestamptz!, $to: timestamptz!) {
booking(where: {_and: [{from: {_lte: $from}}, {to: {_gte: $to}}]}) {
id
from
to
}
}
Run Code Online (Sandbox Code Playgroud)
以上是我尝试过但没有成功的方法。任何人都可以帮助找出检查范围内或用户新预订内是否有任何预订的正确查询是什么?
我们想分别考虑两者from
,to
并对两者应用一个范围。因此,您可以执行以下操作:
query CheckBooking($from: timestamptz!, $to: timestamptz!) {
booking(where: {_or: [
{_and: [{from: {_gte: $from}}, {from: {_lt: $to}}]},
{_and: [{to: {_gt: $from}}, {to: {_lte: $to}}]},
]}) {
id
from
to
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2019 次 |
最近记录: |