日期之间的 Hasura graphql 查询

Hasura graphql query between dates

在我的 hasura.io 数据库中,我有一个 booking table,我在其中存储具有以下属性的预订:

现在,从UI开始,当用户进行预订时,我想检查之前是否有任何预订触及这些日期的范围。

例如。用户想要预订以下日期:

{
  "from": "2020-03-31T14:00:00+00:00",
  "to": "2020-03-31T17:00:00+00:00"
}

但同一天有一个预订:

{
  "from": "2020-03-31T15:00:00+00:00",
  "to": "2020-04-01T17:00:00+00:00"
}

Notice, this booking is been made not within the range of the dates the user is trying to book. So the following query will return nothing.

query CheckBooking($from: timestamptz!, $to: timestamptz!) {
  booking(where: {_and: [{from: {_lte: $from}}, {to: {_gte: $to}}]}) {
    id
    from
    to
  }
}

以上是我试过没有成功的方法。 谁能帮忙弄清楚 检查是否有任何预订在 用户新预订范围内或范围内的正确查询是什么?

我们想分别考虑 fromto,并对两者应用一个范围。所以你可以这样做:

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
  }
}