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

Parameter 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

  1. The following query gets a reference to the function named increment in the current database:

    Copied!
    ('increment')
    ("increment")
    Query metrics:
    •    bytesIn:  24

    •   bytesOut:  81

    • computeOps:   1

    •    readOps:   0

    •   writeOps:   0

    •  readBytes:   0

    • writeBytes:   0

    •  queryTime: 8ms

    •    retries:   0

  2. The following query gets a Reference to the function named increment in a child database named "child_db":

    Copied!
    ('increment', ('child_db'))
    ("increment", ("child_db"))
    Query metrics:
    •    bytesIn:  56

    •   bytesOut: 160

    • computeOps:   1

    •    readOps:   0

    •   writeOps:   0

    •  readBytes: 155

    • writeBytes:   0

    •  queryTime: 9ms

    •    retries:   0

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

    Copied!
    (('increment'))
    {
      ref: ("increment"),
      ts: 1624310406060000,
      name: 'increment',
      body: (("X", (("X"), 1)))
    }
    Query metrics:
    •    bytesIn:  32

    •   bytesOut: 212

    • computeOps:   1

    •    readOps:   1

    •   writeOps:   0

    •  readBytes: 101

    • writeBytes:   0

    •  queryTime: 5ms

    •    retries:   0

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!