Function

Function( name, [database] )
Function( name, [database] )
Function( name, [database] )
Function( name, [database] )
function( name, [database] )
Function( 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:

Value result = await client.Query(
  Function("increment")
);

IResult<Value> data = result.To<Value>();
data.Match(
  Success: value => Console.WriteLine($"{value}"),
  Failure: error => Console.WriteLine($"Query failed:\n{error}")
);
RefV(id = "increment", collection = RefV(id = "functions"))
curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "function": "increment" }'
HTTP/1.1 200 OK
{ "resource": { "@ref": "functions/increment" } }
result, err := client.Query(
  f.Function("increment"))

if (err != nil) {
  fmt.Println(err)
} else {
  fmt.Println(result)
}
{increment 0xc000436090 0xc000436090 <nil>}
System.out.println(
    client.query(
        Function("increment")
    ).get());
ref(id = "increment", collection = ref(id = "functions"))
client.query(
  q.Function('increment')
)
.then((ret) => console.log(ret))
Function("increment")
print(client.query(
  q.function("increment")
))
Ref(id=increment, collection=Ref(id=functions))
println(Await.result(
  client.query(
    Function("increment")
  ),
  5.seconds
))
ref(id = "increment", collection = ref(id = "functions"))

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

Value result = await client.Query(
  Get(Function("increment"))
);

IResult<Value> data = result.To<Value>();
data.Match(
  Success: value => Console.WriteLine($"{value}"),
  Failure: error => Console.WriteLine($"Query failed:\n{error}")
);
ObjectV(ref: RefV(id = "increment", collection = RefV(id = "functions")),ts: LongV(1581379483580000),name: StringV(increment),body: QueryV(System.Collections.Generic.Dictionary`2[System.String,FaunaDB.Query.Expr]))
Not available in this language yet.
result, err := client.Query(
  f.Get(f.Function("increment")))

if (err != nil) {
  fmt.Println(err)
} else {
  fmt.Println(result)
}
map[body:{[123 34 108 97 109 98 100 97 34 58 34 88 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 88 34 125 44 49 93 125 125]} name:increment ref:{increment 0xc00016ed80 0xc00016ed80 <nil>} ts:1581379483580000]
System.out.println(
    client.query(
        Get(Function("increment"))
    ).get());
{ref: ref(id = "increment", collection = ref(id = "functions")), ts: 1581379483580000, name: "increment", body: QueryV({lambda=X, expr={add=[{var=X}, 1]}})}
client.query(
  q.Get(q.Function('increment'))
)
.then((ret) => console.log(ret))
{ ref: Function("increment"),
  ts: 1581379483580000,
  name: 'increment',
  body: Query(Lambda("X", Add(Var("X"), 1))) }
print(client.query(
  q.get(q.function("increment"))
))
{'ref': Ref(id=increment, collection=Ref(id=functions)), 'ts': 1581379483580000, 'name': 'increment', 'body': Query({'lambda': 'X', 'expr': {'add': [{'var': 'X'}, 1]}})}
println(Await.result(
  client.query(
    Get(Function("increment"))
  ),
  5.seconds
))
{ref: ref(id = "increment", collection = ref(id = "functions")), ts: 1581379483580000, name: "increment", body: {lambda: "X", expr: {add: [{var: "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!