List all functions

Reading or writing database documents requires an admin key.

Problem

You need to retrieve a list of all functions within the current database.

Solution

Use the Functions function combined with the Paginate function:

try
{
    Value result = await client.Query(
        Paginate(Functions())
    );
    Console.WriteLine(result);
}
catch (Exception e)
{
    Console.WriteLine($"ERROR: {e.Message}");
}
ObjectV(data: Arr(RefV(id = "increment", collection = RefV(id = "functions")), RefV(id = "double", collection = RefV(id = "functions")), RefV(id = "submit_order", collection = RefV(id = "functions")), RefV(id = "create_post", collection = RefV(id = "functions"))))
result, err := client.Query(
	f.Paginate(f.Functions()))

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
map[data:[{increment 0xc0000924b0 0xc0000924b0 <nil>} {double 0xc0000925a0 0xc0000925a0 <nil>} {submit_order 0xc000092690 0xc000092690 <nil>} {create_post 0xc000092780 0xc000092780 <nil>}]]
System.out.println(
    client.query(
        Paginate(Functions())
    ).get());
{data: [ref(id = "increment", collection = ref(id = "functions")), ref(id = "double", collection = ref(id = "functions")), ref(id = "submit_order", collection = ref(id = "functions")), ref(id = "create_post", collection = ref(id = "functions"))]}
client.query(
  q.Paginate(q.Functions())
)
.then((ret) => console.log(ret))
.catch((err) => console.error(
  'Error: [%s] %s: %s',
  err.name,
  err.message,
  err.errors()[0].description,
))
{
  data: [
    Function("increment"),
    Function("double"),
    Function("submit_order"),
    Function("create_post")
  ]
}
result = client.query(
  q.paginate(q.functions())
)
print(result)
{'data': [Ref(id=increment, collection=Ref(id=functions)), Ref(id=double, collection=Ref(id=functions)), Ref(id=submit_order, collection=Ref(id=functions)), Ref(id=create_post, collection=Ref(id=functions))]}
Paginate(Functions())
{
  data: [
    Function("increment"),
    Function("double"),
    Function("submit_order"),
    Function("create_post")
  ]
}
Query metrics:
  •    bytesIn:   31

  •   bytesOut:  301

  • computeOps:    1

  •    readOps:    8

  •   writeOps:    0

  •  readBytes:  376

  • writeBytes:    0

  •  queryTime: 17ms

  •    retries:    0

Discussion

The Paginate function defaults to returning up to 64 functions per page. If your database contains more than 64 functions, you can use the size parameter to retrieve up to 100,000 functions at once.

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!