【问题标题】:How to query a range of values with Fauna and FQL?如何使用 Fauna 和 FQL 查询一系列值?
【发布时间】:2021-01-28 04:58:59
【问题描述】:

我对 FaunaDB 有疑问。我是新手,浏览过文档,但没有运气。我现在会立即向您展示代码,但 SO 抱怨我的问题中有太多代码。

我正在尝试使用 FQL 执行以下 SQL 语句:

SELECT * FROM order
  WHERE cid = '1234'
  AND fulfilled = false
  AND rank >= 0
  AND rank <= 100 

我尝试了以下方法:

q.Paginate(
  q.Intersection(
    q.Match(
      q.Index('order_by_cid'),
      '1234',
    ),
    q.Match(
      q.Index('order_by_status'),
      false,
    ),
    q.Range(
      q.Match('order_by_rank'),
      [0],
      [100]
    ),
  )
)

但这会返回{ data: [] }

我的索引:

{
  ref: Index("order_by_cid"),
  ts: 1602095185756000,
  active: true,
  serialized: true,
  name: "order_by_cid",
  source: Collection("order"),
  terms: [{ field: ["data", "cid"] }],
  partitions: 1
}

{
  ref: Index("order_by_status"),
  ts: 1602163027885000,
  active: true,
  serialized: true,
  name: "order_by_status",
  source: Collection("order"),
  terms: [{ field: ["data", "fulfilled"] }],
  partitions: 1
}

{
  ref: Index("order_by_rank"),
  ts: 1602611790710000,
  active: true,
  serialized: true,
  name: "order_by_rank",
  source: Collection("order"),
  values: [{ field: ["data", "rank"] }, { field: "ref" }],
  partitions: 8
}

【问题讨论】:

    标签: faunadb


    【解决方案1】:

    索引应该是:

    CreateIndex(
      {
        name:'refByCidFulfilled',
        source:Collection("order"),
        terms:[{field:['data','cid']},{field:['data','fulfilled']}],
        values:[{field:['data','rank']},{field:['ref']}]
      }
    )
    

    你可以查询

    Map(
      Paginate(
        Range(
          Match('refByCidFulfilled',[1234,false]),[1],[100])),
          Lambda(['rank','ref'],Get(Var('ref')
        )
      )
    )
    

    【讨论】:

    • 感谢@Luigi Servini,这行得通!即使您的代码中有放错位置的括号
    猜你喜欢
    • 2017-09-27
    • 1970-01-01
    • 2021-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多