Check out v4 of the Fauna CLI
v4 of the Fauna CLI is now in beta. The new version introduces enhancements to the developer experience, including an improved authentication workflow. To get started, check out the CLI v4 quick start. |
Function.where()
Signature
Function.where(predicate: () => Boolean)) => <Function>
Function.where(predicate: (val: Function) => Boolean)) => <Function>
Description
Each user-defined function (UDF) document in a Fauna database is
represented by a function object. The Function.where()
method returns
the Set of accessible UDF documents that match the predicate function.
If Function.where()
is the last value in a query, the first page of the
Set is returned.
Staged schema
If a database has staged schema, this method interacts with the database’s staged schema, not the active schema.
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
predicate |
Anonymous Function that compares values in each UDF document and
returns |
predicate parameters:
Parameter | Type | Required | Description |
---|---|---|---|
val |
UDF object to compare. If omitted, use dot notation to access Function properties. |
Examples
Get the Set of UDF documents that are accessible and match the predicate function:
Function.where(.name.includes('validate'))
{
data: [
{
name: "validateOrderStatusTransition",
coll: Function,
ts: Time("2099-10-25T17:49:28.145Z"),
body: <<-END
(oldStatus, newStatus) => {
if (oldStatus == "cart" && newStatus != "processing") {
abort("Invalid status transition.")
} else if (oldStatus == "processing" && newStatus != "shipped") {
abort("Invalid status transition.")
} else if (oldStatus == "shipped" && newStatus != "delivered") {
abort("Invalid status transition.")
}
}
END
}
]
}
Is this article helpful?
Tell Fauna how the article can be improved:
Visit Fauna's forums
or email docs@fauna.com
Thank you for your feedback!