FQL v4 will be decommissioned on June 30, 2025. Ensure that you complete your migration from FQL v4 to FQL v10 by that date. For more details, review the migration guide. Contact support@fauna.com with any questions. |
CreateFunction
This reference topic applies to FQL v4. Go to this page for the latest FQL v10 reference topics. |
CreateFunction( param_object )
create_function( param_object )
CreateFunction( param_object )
CreateFunction( param_object )
CreateFunction( param_object )
Description
The CreateFunction
operation adds a new user-defined function with the
specified parameters.
Parameters
Parameter | Type | Definition and Requirements |
---|---|---|
|
Object |
The |
param_object
Field Name | Field Type | Definition and Requirements | ||
---|---|---|---|---|
|
String |
The name of the function. Cannot be |
||
|
Object |
The FQL instructions to be executed. |
||
|
Object |
Optional - This is user-defined metadata for the user-defined function. It is provided for the developer to store information at the function level. |
||
|
Object or |
Optional - Specifies the role that should be used when the user-defined function is called, which would typically be used to provide privilege escalation when current privileges would otherwise be too restrictive. To use a built-in role, specify one of the strings
|
Returns
An object containing the metadata of CreateFunction
operations.
Field Name | Field Type | Definition and Requirements |
---|---|---|
|
Reference |
The reference is an automatically-generated, unique identifier within the database to identify the function that was created. |
|
String |
The logical name of the function created. |
|
Object or |
The role that should be used when the function is called. Only included
when |
|
Long |
The timestamp, with microsecond resolution, associated with the creation of the function. |
|
Object |
The FQL instructions to be executed. |
Examples
The following query creates a user-defined function called "double":
{
ref: Function("double"),
ts: 1591997162610000,
name: 'double',
body: Query(Lambda("x", Add(Var("x"), Var("x"))))
}
{'ref': Ref(id=double, collection=Ref(id=functions)), 'ts': 1611102297910000, 'name': 'double', 'body': Query({'api_version': '4', 'lambda': 'x', 'expr': {'add': [{'var': 'x'}, {'var': 'x'}]}})}
map[body:{[123 34 97 112 105 95 118 101 114 115 105 111 110 34 58 34 52 34 44 34 108 97 109 98 100 97 34 58 34 120 34 44 34 101 120 112 114 34 58 123 34 97 100 100 34 58 91 123 34 118 97 114 34 58 34 120 34 125 44 123 34 118 97 114 34 58 34 120 34 125 93 125 125]} name:double ref:{double 0xc000178270 0xc000178270 <nil>} ts:1631915951360000]
ObjectV(ref: RefV(id = "double", collection = RefV(id = "functions")),ts: LongV(1611102338170000),name: StringV(double),body: QueryV(System.Collections.Generic.Dictionary`2[System.String,FaunaDB.Query.Expr]))
{
ref: Function("double"),
ts: 1631916677410000,
name: 'double',
body: Query(Lambda("x", Add(Var("x"), Var("x"))))
}
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!