如何使用 Fauna 和 FQL 查询一系列值?
How to query a range of values with Fauna and FQL?
我在使用 FaunaDB 时遇到了问题。我是新手,看过文档,但没有运气。我现在会直接向您展示代码,但抱怨我的问题中包含太多代码。
我正在尝试使用 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]
),
)
)
但是这个returns{ 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
}
索引应该是:
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')
)
)
)
我在使用 FaunaDB 时遇到了问题。我是新手,看过文档,但没有运气。我现在会直接向您展示代码,但抱怨我的问题中包含太多代码。
我正在尝试使用 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]
),
)
)
但是这个returns{ 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
}
索引应该是:
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')
)
)
)