DevTips -- FaunaDB

moon indicating dark mode
sun indicating light mode
FaunaDB is a global serverless database that gives you ubiquitous, low latency access to app data, without sacrificing data correctness. It eliminates layers of app code for manually handling data anomalies, security, and scale, creating a friendlier dev experience for you and better app experience for your users.

Passing options to Paginate

\@fauna DB's Paginate function operates on cursors. https://egghead.io/lessons/faunadb-paginating-and-passing-other-options-with-paginate?pl=the-complete-guide-to-faunadb-74bef44b?af=7h4hd0

Paginate(
Match(Index("all_customers")),
{
size: 2,
after: Ref(Collection("customers"), "244075679455381001")
}
)
// an example return value
{
"before": [
Ref(Collection("customers"), "244075679455381001")
],
"data": [
Ref(Collection("customers"), "244075679455381001"),
Ref(Collection("customers"), "244987940566991369")
]
}

Array Operations on Pages

When using @faunadb's FQL, the Page type that is returned from Paginate() calls can be used in array methods, which "see through" the Page structure to the contained array.

Map(
Paginate(Match(Index("all_customers"))),
Lambda(
"X",
Select(["data", "firstName"],
Get(Var("X"))
)
)
)
// an example document in the index
{
"firstName": "Auria",
"lastName": "Osgardby",
"address": {
"street": "87856 Mendota Court",
"city": "Idaho Falls",
"state": "ID",
"zipCode": "83405"
},
"telephone": "208-346-0715",
"creditCard": {
"network": "Visa",
"number": "4556781272473393"
}
}
// result of `Paginate(Match(Index("all_customers")))`
{
"data": [
Ref(Collection("customers"), "244075679454331401"),
Ref(Collection("customers"), "244075679455379977"),
Ref(Collection("customers"), "244075679455381001")
]
}
// result of Map query on Paginate results
{
"data": [
"Auria",
"Skipper",
"Ardith"
]
}