User-defined functions

FQL v4 UDFs and FQL v10 UDFs are cross-compatible. Each version can call a function written in the other version but you can’t create an FQL v10 UDF using FQL v4 syntax.

reference:

User-defined functions (UDFs) are documents that exist in a Fauna internal functions collection and can be called by name. Each function document is stored in the context of the enclosing database. Peer, parent, and child databases store functions independently.

Because UDFs execute in the Fauna service, UDFs enable you to embed your business logic in the Fauna service and reduce the complexity of your client-side applications.

The top-level Function object includes methods for managing functions.

When a function is deleted, its definition and associated data become inaccessible, and the data is deleted asynchronously.

UDFs are handled the same as other queries and are subject to the same Global limits.

Signature

The signature of a UDF defines two parameters:

  • a parameter list

  • an executable query expression

The parameter list specifies the parameter names passed to the function on execution. The parameter list can be a single String name or an array of string names.

The query expression is any valid FQL query.

To use named parameters in the query expression, use the Var function.

Permissions

By default, UDFs run with the privileges of the current query session. For example, if your client code connects to Fauna using a "client" key, any called UDFs, by default, execute with "client" privileges.

You can specify a role for named UDFs, which grants the functions of the named role while the UDF executes. This feature is similar to the Unix setuid permission setting. For example, a function whose role field is set to admin can make the same query that an admin key allows, even for sessions authenticated with a client key.

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!