I use a local instance of Fauna to test my development. My functions to interact with the database (using Netlify) all work using V4
Now, to test on the latest version of fauna, I cannot create an index in fauna shell using V4 syntax, e.g.
CreateIndex({
name: "users_by_username",
source: Collection("users"),
terms: [{ field: ["data", "username"] }],
})
but I can using V10 syntax
users.definition.update({ indexes: { users_by_username: { terms: [{ field: ".username" }] } } })
My V4 code does not find this index.
Can I use V4 syntax on a local instance of fauna?
Indexes are one of the big differences between versions. You can interop with indexes using UDFs.
For example, you can use a v4 Index in v10 with a UDF defined using v4
// FQL v4
CreateFunction({
name: "useV4Index",
body: Query(Lambda(
["term1", "term2"],
Paginate(Match(Index("things_by_stuff"), Var("term1"), Var("term2")))
))
})
// later in FQL v10
useV4Index("a", "b")
Or you can use a v10 Index in v4 with a UDF defined using v10. Note that the v10 Set
type cannot be rendered in v4, so you ned to materialize it using the paginate
method.
// FSL
function useV10Index(term1, term2) {
things.by_stuff(term1, term2).paginate(64)
}
// later in FQL v4
Call(Function("useV10Index"), "a", "b")
But when I use CreateFunction in fauna shell it complains
error: Unbound variable CreateFunction
You cannot interchange v4 and v10 syntax. The latest dashboard only issues v10 requests. Please use the v4 dashboard to issue v4 queries.
You can also use the Fauna Shell with the --version 4
option.
system
Closed
January 7, 2024, 1:30pm
5
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.