CreateFunction
CreateFunction( param_object )
Description
The CreateFunction
operation adds a new user-defined function with the
specified parameters.
Parameters
Argument | Type | Definition and Requirements |
---|---|---|
|
Object |
The param_object fields are described below. |
param_object
Field Name | Field Type | Definition and Requirements | ||
---|---|---|---|---|
|
The logical name of the function. |
|||
|
The Fauna Query Language instructions to be executed. |
|||
|
Optional - This is user-defined metadata for the user-defined function. It is provided for the developer to store information at the function level. |
|||
|
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 |
---|---|---|
|
The reference is an automatically-generated, unique identifier within the database to identify the function that was created. |
|
|
The logical name of the function created. |
|
|
The role that should be used when the function is called. Only included
when |
|
|
The timestamp, with microsecond resolution, associated with the creation of the function. |
|
|
The Fauna Query Language instructions to be executed. |
Examples
The following query creates a user-defined function called "double":
client.query(
q.CreateFunction({
name: 'double',
body: q.Query(
q.Lambda('x', q.Add(q.Var('x'), q.Var('x')))
),
})
)
.then((ret) => console.log(ret))
{ ref: Ref(id=double, collection=Ref(id=functions)),
ts: 1527275011179623,
name: 'double',
body: Query("[object Object]") }
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!