- 在 FaunaDB 中最有效的方法是什么?
假设您具有以下索引,则可以使用 Range 函数完成该查询:
> CreateIndex({
name: "sal_by_deptno",
source: Collection("emp"),
terms: [ { field: ['data', 'deptno'] } ],
values: [ { field: ['data', 'sal'] }, { field: 'ref' } ]
})
你可以这样查询:
> Paginate(Range(Match(Index("sal_by_deptno"), 10), [2000], []))
{
data: [
[ 2000, Ref(Collection("emp"), "260259607265411603") ],
[ 3000, Ref(Collection("emp"), "260259610695303699") ]
]
}
- #1 可以使用intersection() 函数完成吗?
交集(和其他集合函数)仅在所有操作数具有相同格式的情况下才有效,因此我认为它在这种情况下不会有用。
- 如果您想进行以下查询,如何使用 FQL 完成?
Paginate(
Union(
Range(Match(Index("sal_by_deptno"), 10), [2000], []),
Range(Match(Index("sal_by_deptno"), 10), [], [499.99])
)
)
Or 等价于联合,因此这是您应该在该上下文中使用的函数。请记住,Range 函数具有包容性,因此要模拟
- FQL 中的这个查询怎么样?
您需要第二个索引,然后使用 Join 功能
CreateIndex({
name: "age_by_ref",
source: Collection("emp"),
terms: [{field: 'ref'}],
values: [{field: ['data', 'age']}, {field: 'ref'}]
})
然后用这个查询:
Paginate(
Join(
Union(
Range(Match(Index("sal_by_deptno"), 10), [2000], []),
Range(Match(Index("sal_by_deptno"), 10), [], [499.99])
),
Lambda((sal, ref) => Range(Match(Index("age_by_ref"), ref), [22], []))
)
)
上述解决方案绝不是最终解决方案,这只是我在回答这个问题时突然出现的一种可能的解决方案。