DEV Community

Cover image for Announcing UDF in Console
Fauna for Fauna, Inc.

Posted on • Updated on • Originally published at fauna.com

Announcing UDF in Console

Author: Lewis King
Date: December 19, 2019
Originally posted on the Fauna blog.


We’re pleased to announce the release of user-defined function (UDF) support in the FaunaDB Console! While UDFs have been available in FQL for some time, they can now be easily managed using the Console GUI.

Generally speaking, a UDF is comparable to a stored procedure or server-side function that has its parameters set by a user and often is seen as a “programming shortcut”. In FaunaDB, UDFs are FQL Lambda functions (which can be anonymous), and they can be exposed through the GraphQL API, by using the @resolver directive on fields in the Query and Mutation types. You can learn more about FaunaDB GraphQL UDFs in our documentation.

UDFs in action

Creating UDFs in the Console is quite simple. From the homepage, click on one of your Databases. In the left-hand navigation bar, click on the “Functions” button and then click the green “New Function button”:
Alt Text

You’ll then see the New Function screen. For this example, let’s create a function that simply doubles the input for a query (more advanced examples are given here). This query adds the variable “x” to itself, thereby doubling it.

Let’s call the function “double”, and specify the function body as:

Query(
Lambda('x', Add(Var('x'), Var('x')))
)
Enter fullscreen mode Exit fullscreen mode

Alt Text

Once saved, you should see the function listed in the Functions list:

Alt Text

Note: you can use the Role field to apply a role’s privileges to a UDF, which is how you specify permissions in FaunaDB.

You can create more functions at your whim, and delete functions when needed:

Alt Text

Using your new function is straightforward as well. Simply wrap the function name in quotes in a Call()command, i.e. Call("double", 2):

Alt Text

And that’s about it! When it comes to UDFs, the only limit is your creativity 😉

Conclusion

With our latest cloud release, users now have the ability to create and manage UDFs for a database directly in the FaunaDB Console.

Visit our documentation to learn more. Please reach out to me on Twitter and our Community Slack and describe any other features that would make FaunaDB an obvious choice for your next project.

Top comments (0)