Function

Copied!
( name, [database] )

Description

The Function function returns a Reference for the specified function name in the specified child database. If a child database is not specified, the returned function reference belongs to the current database.

When a child database is specified, an admin key must be used to call Function (server or client keys, or ABAC tokens, cannot be used to access a child database).

Parameters

Argument Type Definition and Requirements

name

The name of a function.

database

Optional - A reference to a child database. If not specified, the current database is used.

Returns

A reference to a function with the specified name, in the specified child database (or the current database if database is not specified).

Examples

The following query gets a reference to the function named increment:

Copied!
client.query(
  q.('increment')
)
.then((ret) => console.log(ret))
("increment")

The following query demonstrates how to retrieve the function document by its reference:

Copied!
client.query(
  q.(q.('increment'))
)
.then((ret) => console.log(ret))
{ ref: ("increment"),
  ts: 1581379483580000,
  name: 'increment',
  body: (("X", (("X"), 1))) }

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!