TOPICS
LANGUAGE

Query Language API

Introduction

The Fauna Query Language (FQL) is the primary interface for interacting with a FaunaDB cluster.

While not a general-purpose programming language, it provides much of the functionality expected from one. It allows for complex, precise manipulation and retrieval of data stored within FaunaDB.

The language is expression-oriented: all functions, control structures, and literals return values. So it is easy, for example, to group multiple results together by combining them into an Array or Object, or map over a collection and compute a result–possibly fetching more data–for each member.

A query is executed by submitting it to a FaunaDB cluster, which computes and returns the result. Query execution is transactional: No changes are committed if something goes wrong. If a query fails, an error response is returned instead of a result.

This API reference contains descriptions of all functions and expressions provided by the query language.

Imports

Each FaunaDB driver will require an import stanza. For more detailed platform installation instructions, consult the README for your particular driver.


Not applicable

using FaunaDB.Client;
using FaunaDB.Types;

using static FaunaDB.Query.Language;

import com.faunadb.client.FaunaClient;
import static com.faunadb.client.query.Language.*;

import (
  "fmt"

  f "github.com/fauna/faunadb-go/faunadb"
)

import faunadb.FaunaClient
import faunadb.query._

from faunadb import query as q
from faunadb.objects import Ref
from faunadb.client import FaunaClient

require 'fauna'

import FaunaDB

var faunadb = require('faunadb'),
  q = faunadb.query;

Data Types

FQL supports a comprehensive set of data types which are broken down into four categories: simple types, special types, Collection Type and complex types. A simple data type is one that is native to FaunaDB and also native to JSON. Special data types in FaunaDB extend the limited number of native JSON data types. The complex data type, is a composite of other existing data types. The collection data type, is able to handle multiple items while maintaining order.

Simple Type Special Type Complex Type Collection Type
  • Boolean
  • Null
  • Number
  • String
  • Bytes
  • Date
  • Query
  • Ref
  • Set
  • Timestamp
  • Object
  • Instance
  • Instance Event
  • Set Event
  • Array
  • Page

Simple Type

Simple data types contain a key and simple value which is native to both Fauna and JSON. For example, a string containing the word “cat” or a number with the value 21.

Boolean

The boolean data type can only store “true” or “false” values. These can be directly compared for equality or inequality. They can also be compared to the Boolean literal values of true and false.

Null

Null is a special marker used to indicate that a data value does not exist. It is a representation of missing information. A null value indicates a lack of a value. A lack of a value is not the same thing as a value of zero, in the same way that a lack of an answer is not the same thing as an answer of “no”. Null is a value that can be directly compared for application programmer simplicity. This means that Null == Null returns true.

Number

Numbers are any real number which are bounded by double precision (64-bit), such as 3, -27, 3.1415. (Neither infinity nor NaN are allowed.)

String

String data types store any letters, numbers, whitespaces, and/or symbols in a fixed order.

Special Type

FaunaDB supports types beyond those native to JSON. These types are referred to as Special Types and are encoded as JSON objects with a single field. The field name is one of several type tags that specify the type of the value. Type tags always start with @.

Bytes

@bytes denotes a base64 encoded string representing a byte array.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "@bytes": "AQID" }'

client.Query(new BytesV(0x1, 0x2, 0x3));

System.out.println(client.query(Value(new byte[]{ 0x1, 0x2, 0x3 })).get());

result, _ := client.Query(f.BytesV{0x1, 0x2, 0x3})

fmt.Println(result)

client.query(Array[Byte](0x1, 0x2, 0x3))

client.query(bytearray(b'\x01\x02\x03'))

$client.query do
  Fauna::Bytes.new("\01\02\03")
end

client.query(BytesV(fromArray: [0x1, 0x2, 0x3]))

client.query(new Uint8Array([0x1, 0x2, 0x3]))
  .then((ret) => console.log(ret));

=> HTTP/1.1 200 OK
{ "resource": { "@bytes": "AQID" } }

=> { "@bytes": "AQID" }

=> [0x01 0x02 0x03]

=> [1 2 3]

=> { "@bytes": "AQID" }

=> { "@bytes": "AQID" }

=> { "@bytes": "AQID" }

=> { "@bytes": "AQID" }

=> Bytes("AQID")

Date

@date denotes a date, with no associated time zone.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "@date": "1970-01-01" }'

client.Query(Date("1970-01-01"));

System.out.println(client.query(Date(Value("1970-01-01"))).get());

result, _ := client.Query(f.Date("1970-01-01"))

fmt.Println(result)

client.query(Date("1970-01-01"))

client.query(q.date("1970-01-01"))

$client.query do
  date '1970-01-01'
end

client.query(DateFn("1970-01-01"))

client.query(q.Date("1970-01-01"))
  .then((ret) => console.log(ret));

=> HTTP/1.1 200 OK
{ "resource": { "@date": "1970-01-01" } }

=> { "@date": "1970-01-01" }

=> 1970-01-01

=> {0 62135596800 <nil>}

=> { "@date": "1970-01-01" }

=> { "@date": "1970-01-01" }

=> { "@date": "1970-01-01" }

=> { "@date": "1970-01-01" }

=> FaunaDate { value: '1970-01-01' }

Query

@query denotes a query expression object.

Ref

@ref denotes a resource ref. Refs may be extracted from instances, or constructed using the ref function.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "@ref": "classes/spells/181388642071085568" }'

client.Query(Select("ref", Get(Class("spells"))));

System.out.println(client.query(Select(Value("ref"), Get(Class("spells")))).get());

result, _ := client.Query(f.Select("ref", f.Get(f.Class("spells"))))
fmt.Print(result)

print client.query(q.select("ref", q.get(q.class_("spells"))))

puts $client.query { select "ref", get(class_("spells")) }

client.query(Select("ref", Get(Class("spells"))))

client.query(q.Select("ref", q.Get(q.Class("spells"))))
  .then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{ "resource": { "@ref": "classes/spells/181388642071085568" } }

=> { "@ref": "classes/spells/181388642071085568" }

=> ref(id = "spells", class = ref(id = "classes"))

=> {spells 0xc4201f4a60 <nil>}

=> RefV(id = "spells", class = RefV(id = "classes"))

=> Ref(id=spells, class=Ref(id=classes))

=> Ref(id=spells,class=Ref(id=classes))

=> { "@ref": "classes/spells/181388642071085568" }

=> Ref(id=spells, class=Ref(id=classes))

curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "ref": { "class": "spells" }, "id": "1" }'

client.Query(Ref(Class("spells"), "1"));

System.out.println(client.query(Ref(Class(Value("spells")),Value(1))).get());

result, _ := client.Query(f.RefClass(f.Class("spells"), "1"))

fmt.Println(result)

client.query(Ref(Class("spells"), "1"))

client.query(Ref(q.class_expr("spells"), "1"))

$client.query do
  ref class_('spells'), '1'
end

client.query(Ref(class: Class("spells"), id: "1"))

client.query(q.Ref(q.Class("spells"), "1"));
  .then((ret) => console.log(ret));

=> HTTP/1.1 200 OK
{ "resource": { "@ref": "classes/spells/1" } }

=> { "@ref": "classes/spells/1" }

=> ref(id = "1", class = ref(id = "spells", class = ref(id = "classes")))

=> {1 0xc420138620 <nil>}

=> { "@ref": "classes/spells/1" }

=> { "@ref": "classes/spells/1" }

=> { "@ref": "classes/spells/1" }

=> { "@ref": "classes/spells/1" }

=> Ref(id=1, class=Ref(id=spells, class=Ref(id=classes)))

Set

@set denotes a set identifier.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{
          "@set": {
            "match": { "@ref": "indexes/spells_by_element" },
            "terms": "fire"
          }
        }'

client.Query(Match(Ref("indexes/spells_by_element"), "fire"));

System.out.println(
        client.query(
                Match(
                     Index(Value("spells_by_element")),
                     Value("fire")
                )
        ).get());

result, _ := client.Query(
  f.MatchTerm(f.Index("spells_by_element"), "fire"),
)

fmt.Println(result)

client.query(Match(Ref("indexes/spells_by_element"), "fire"))

client.query(q.match(Ref("indexes/spells_by_element"), "fire"))

$client.query do
  match ref('indexes/spells_by_element'), 'fire'
end

client.query(
    Match(
        index: Ref("indexes/spells_by_element"),
        terms: "fire"
    )
)

client.query(q.Match(q.Index("spells_by_element"), "fire"))
  .then((ret) => console.log(ret));

=> HTTP/1.1 200 OK
{
  "resource": {
    "@set": {
      "match": { "@ref": "indexes/spells_by_element" },
      "terms": "fire"
    }
  }
}

=> {
  "@set": {
    "match": { "@ref": "indexes/spells_by_element" },
    "terms": "fire"
  }
}

=> {@set = {match: ref(id = "spells_by_element", class = ref(id = "indexes")), terms: "fire"}}

=> {map[match:{spells_by_element 0xc4201a6360 <nil>} terms:fire]}

=> {
  "@set": {
    "match": { "@ref": "indexes/spells_by_element" },
    "terms": "fire"
  }
}

=> {
  "@set": {
    "match": { "@ref": "indexes/spells_by_element" },
    "terms": "fire"
  }
}

=> {
  "@set": {
    "match": { "@ref": "indexes/spells_by_element" },
    "terms": "fire"
  }
}

=> {
  "@set": {
    "match": { "@ref": "indexes/spells_by_element" },
    "terms": "fire"
  }
}

=> SetRef({"match":{"@ref":{"id":"spells_by_element","class":{"@ref":{"id":"indexes"}}}},"terms":"fire"})

Timestamp

@ts stores an instant in time expressed as a calendar date and time of day in UTC. Timestamp can safely store nanoseconds precision, but be careful as many operating system clocks provide only microsecond precision. Timestamps may be inserted with offsets, but will be canonicalized to UTC; the offset component will be lost. A time must be within the range -999999999-01-01T00:00:00Z - 9999-12-31T23:59:59.999999999Z.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "time": "1970-01-01T00:00:00Z" }'

client.Query(Time("1970-01-01T00:00:00Z"));

System.out.println(client.query(Time(Value("1970-01-01T00:00:00Z"))).get());

result, _ := client.Query(f.Time("1970-01-01T00:00:00Z"))

fmt.Println(result)

client.query(Time("1970-01-01T00:00:00Z"))

client.query(q.time("1970-01-01T00:00:00Z"))

$client.query do
  time '1970-01-01T00:00:00Z'
end

client.query(Time(fromString: "1970-01-01T00:00:00Z"))

client.query(q.Time("1970-01-01T00:00:00Z"))
  .then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{ "resource": { "@ts": "1970-01-01T00:00:00Z" } }

=> { "@ts": "1970-01-01T00:00:00Z" }

=> 1970-01-01T00:00:00Z

=> {0 62135596800 <nil>}

=> { "@ts": "1970-01-01T00:00:00Z" }

=> { "@ts": "1970-01-01T00:00:00Z" }

=> { "@ts": "1970-01-01T00:00:00Z" }

=> { "@ts": "1970-01-01T00:00:00Z" }

=> FaunaTime { value: '1970-01-01T00:00:00Z' }

Complex Type

Object

Object values are a collection of key/value pairs. The keys must be strings and the values must be valid Fauna data types. Objects evaluate to their contents:


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{
          "object": { "name": "Hen Wen", "age": { "add": [ 100, 10 ] } }
        }'

client.Query(Obj("name", "Hen Wen", "age", Add(100, 10)));

System.out.println(
  client.query(
    Obj("name", Value("Hen Wen"), "age", Add(Value(100), Value(10)))
  ).get());

result, _ := client.Query(f.Obj{"name": "Hen Wen", "age": f.Add(100, 10)})

fmt.Println(result)

client.query(Obj("name" -> "Hen Wen", "age" -> Add(100, 10)))

client.query({"name": "Hen Wen", "age": q.add(100, 10)})

$client.query do
  { name: 'Hen Wen', age: add(100, 10) }
end

client.query(
    Obj("name" => "Hen Wen", "age" => Add(100, 10))
)

client.query({ name: "Hen Wen", age: q.Add(100, 10) })
  .then((ret) => console.log(ret));

=> HTTP/1.1 200 OK
{ "resource": { "name": "Hen Wen", "age": 110 } }

=> { "name": "Hen Wen", "age": 110 }

=> { name: "Hen Wen", age: 110 }

=> map[age:110 name:Hen Wen]

=> { "name": "Hen Wen", "age": 110 }

=> { "name": "Hen Wen", "age": 110 }

=> { "name": "Hen Wen", "age": 110 }

=> { "name": "Hen Wen", "age": 110 }

=> { name: 'Hen Wen', age: 110 }

Instance

Instance Event

An Instace Events tracks the history of the instance’s data over time. The events in this history include all create, update, and delete events in the instance’s timeline.

Field Value  
instance Ref The reference to the instance.
action String Either “create”,”update” or “delete”.
ts Integer The microsecond UNIX timestamp at which the event occurred.
data Object Varies based on the action.

Set Event

Set Events are objects that are returned when paginating through an index.

Field Value  
instance Ref The reference to the instance.
action String Either “add” or “remove”.
ts Integer The microsecond UNIX timestamp at which the event occurred.
data Object Exactly as defined by the index..

Collection Type

A collection data types is a group of items. The collection is an array or is an object that contains an array as one of its elements.

Array

An array is a data structure that contains a group of elements. Typically the elements of an array are of the same or related type. When an array is used in FQL it will evaluate to its contents.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '[ 1, 2, { "concat": [ "Hen ", "Wen" ] } ]'

client.Query(Arr(1, 2, Concat(Arr("Hen ", "Wen"))));

System.out.println(client.query(
         Arr(
             Value(1),
             Value(2),
             Concat(Arr(Value("Hen "), Value("Wen")))
         )).get());

result, _ := client.Query(f.Arr{1, 2, f.Concat(f.Arr{"Hen ", "Wen"})})

fmt.Println(result)

client.query(Arr(1, 2, Concat(Arr("Hen ", "Wen"))))

client.query([1, 2, q.concat(["Hen ", "Wen"])])

$client.query do
  [1, 2, concat(['Hen ', 'Wen'])]
end

client.query(Arr(1, 2, Concat("Hen ", "Wen")))

client.query([1, 2, q.Concat(["Hen ", "Wen"])])
  .then((ret) => console.log(ret));

=> HTTP/1.1 200 OK
{ "resource": [ 1, 2, "Hen Wen" ] }

=> [ 1, 2, "Hen Wen" ]

=> [1, 2, "Hen Wen"]

=> [1, 2, Hen Wen]

=> [ 1, 2, "Hen Wen" ]

=> [ 1, 2, "Hen Wen" ]

=> [ 1, 2, "Hen Wen" ]

=> [ 1, 2, "Hen Wen" ]

=> [ 1, 2, 'Hen Wen' ]

Page

A Page contains an array of results and other “decorated” elements. In some cases the entire result set may not fit into the array so other fields (the cursor fields) allow you to walk the results set in blocks (i.e. like pages in a book). The cursor fields retrieve blocks of results before or after the current page of results. When page’s are passed to collection functions, only the array element of the page is examined or transformed. Other elements of the page, such as the cursor, remain unaffected and are passed directly through to the output.

Field Type  
data Array The elements in the page.
after Cursor The cursor for the next page, inclusive. Optional.
before Cursor The cursor for the previous page, exclusive. Optional.

Literal

A literal is a constant value for a given data type. Booleans, Integers, Decimals, Strings, and Null all evaluate to their associated type:

true, false   // Boolean
1, 2          // Integer
3.4, 1.2e10   // Decimal
"a", "b"      // String
null          // Null

Basic Forms

At


At( timestamp, expression )

At( timestamp, expression )

At( timestamp, expression )

At( timesamp, expression )

at( timestamp, expression )

at timestamp, expression

At( timesamp, expression )

At( timestamp, expression )

Description

The At function executes a temporal query, a query which examines the data in the past. The “timestamp” determines the data available for viewing by creating a virtual snapshot of the data which was current at that date and time. All reads from the associated “expression” will then be executed on that virtual snapshot. In contrast, all write operations must be executed at the current time. Attempting a write operation at any other time will produce an error.

Parameters

Argument Type Definition and Requirements
timestamp A Function Ref The date and time of the virtual snapshot of the data.
expression Expressions The FQL statement to be executed.

Returns

The evaluation of the expression at the given timestamp.

Examples

The query below creates a snapshot of the data to read at “1970-01-01” and retrieves all classes that existed on that date.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{
          "at": { "@ts": "1970-01-01T00:00:00Z" },
          "expr": { "paginate": { "@ref": "classes" } }
        }'

client.Query(
  At(Time("1970-01-01T00:00:00Z"), Paginate(Ref("classes"))));

System.out.println(
        client.query(
                At(
                  Time(Value("1970-01-01T00:00:00Z")),
                  Paginate(Ref("classes"))
                )
        ).get());

result, _ := client.Query(
    f.At(
        f.Time("1970-01-01T00:00:00Z"),
        f.Paginate(f.Classes()),
    ),
)

fmt.Println(result)

client.query(
  At(Time("1970-01-01T00:00:00Z"), Paginate(Ref("classes"))))

client.query(
  q.at(
    q.time("1970-01-01T00:00:00Z"),
    q.paginate(Ref("classes"))
  ))

$client.query do
  at time('1970-01-01T00:00:00Z'), paginate(ref('classes'))
end

client.query(
    At(
        timestamp: Time("1970-01-01T00:00:00Z"),
        Paginate(Ref("classes"))
    )
)

client.query(
  q.At(
    q.Time("1970-01-01T00:00:00Z"),
    q.Paginate(q.Classes(null))))
.then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{ "resource": { "data": [ ] } }

=> { "data": [ ] }

=> {data: []}

=> map[data:[]]

=> { "data": [ ] }

=> { "data": [ ] }

=> { "data": [ ] }

=> { "data": [ ] }

=> { data: [] }

Related References

Call


// Not available in this language yet.

Call( function_ref, arguments, ... )

Call( function_ref, arguments, ... )

Call( function_ref, arguments, ... )

# Not available in this language yet.

# Not available in this language yet.

// Not available in this language yet.

Call( function_ref, arguments, ... )

Description

The Call function executes a user-defined function previously defined with the CreateFunction statement. The Call function takes a variable length list of arguments which must match the type and number of the function being called. These arguments are provided to the function being executed by Call.

Parameters

Argument Type Definition and Requirements
function Function Ref A reference to the function. Given the name of the function, use the Function helper statement to retrieve the function’s reference.
arguments Expressions The arguments for the function.

Returns

The evaluation of the function with the given arguments.

Examples

The following example executes a user-defined function with the associated arguments.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "call": { "function": "increment" }, "arguments": 2 }'

// Not available in this language yet.

Expr function_ref = client.query(
    Select(Arr(Value("ref")),
        CreateFunction(
            Obj( "name", Value("increment"),
            "body" , Query(Lambda(Value("x"), Add(Var("x"), Value(1))))
            )
        )
    )
 ).get();

 System.out.println(
         client.query( Call( Function("increment")  , Value(2))
         ).get());

result, _ := client.Query(f.Call(f.Function("increment"), 2))

fmt.Println(result)

// Not available in this language yet.

# Not available in this language yet.

# Not available in this language yet.

// Not available in this language yet.

client.query(q.Call(q.Function("increment"), 2))
  .then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{ "resource": 3 }

=> 3

=> 3

=> 3

=> 3

=> 3

=> 3

=> 3

=> 3

Related References

CreateFunction Statement

Do


Do( expression, ... )

Do( expression, ... )

Do( expression, ... )

Do( expression, ... )

do( expression, ... )

do_( expression, ... )

Do( expression, ... )

Do( expression, ... )

Description

The Do function evaluates a list of expressions which are provided as arguments. This evaluation will occur sequentially, from left to right, ensuring that modifications made by earlier expressions will be seen by later expressions. If one of the expressions evaluated by Do returns an error, the current transaction will be terminated and none of the expressions’ effects will be persisted in the database. If all the expressions executed by Do succeed, only the results of the last statements executed are returned. If no expressions are provided, Do returns an error.

Parameters

Argument Type Definition and Requirements
expression List of Expressions One or more expressions to be evaluated.

Returns

The evaluation of the last expression.

Examples

The query below has a Do statement with two expressions. The first expression creates an instance associated with the “magical_creatures” class with an id of 1. The second expression retrieves the instance from the ref containing the class “magical_creatures” and id of 1. This was the instance just created in the previous statement. Only the results from the second retrieving expression are returned.


curl https://db.fauna.com/ \
    -d '{
          "do": [
            {
              "create": { "ref": { "class": "magical_creatures" }, "id": 1 },
              "params": {
                "object": { "data": { "object": { "name": "Hen Wen" } } }
              }
            },
            {
              "get": { "ref": { "class": "magical_creatures" }, "id": 1 }
            }
          ]
        }'

client.Query(
  Do(
    Create(
      Ref(Class("magical_creatures"), 1),
      Obj("data", Obj("name", "Hen Wen"))),
    Get(Ref(Class("magical_creatures"), 1))));

System.out.println(
    client.query(
        Do(
           Create(
              Ref(Class(Value("magical_creatures")), Value(1)),
              Obj("data", Obj("name", Value("Hen Wen")))
           ),
          Get(Ref(Class(Value("magical_creatures")), Value(1)))
        )
    ).get());

result, _ := client.Query(
    f.Do(
        f.Create(
            f.RefClass(f.Class("magical_creatures"), 1),
            f.Obj{"data": f.Obj{"name": "Hen Wen"}},
        ),
        f.Get(f.RefClass(f.Class("magical_creatures"), 1)),
    ),
)

fmt.Println(result)

client.query(
  Do(
    Create(
      Ref(Class("magical_creatures"), 1),
      Obj("data" -> Obj("name" -> "Hen Wen"))),
    Get(Ref(Class("magical_creatures"), 1))))

client.query(
  q.do(
    q.create(
      Ref(q.class_expr("magical_creatures"), 1),
      {"data": {"name": "Hen Wen"}}
    ),
    q.get(Ref(q.class_expr("magical_creatures"), 1))
  ))

$client.query do
  do_(
    create(ref(class_('magical_creatures'), 1),
           data: { name: 'Hen Wen' }),
    get(ref(class_('magical_creatures'), 1)))
end

client.query(
    Do(
        Create(
            at: Ref(class: Class("magical_creatures"), id: 1),
            Obj("data" => Obj("name" => "Hen Wen"))
        ),
        Get(Ref(class: Class("magical_creatures"), id: 1))
    )
)

client.query(
  q.Do(
    q.Create(
      q.Ref(q.Class("magical_creatures"), 1),
      { data: { name: "Hen Wen" } }),
    q.Get(q.Ref(q.Class("magical_creatures"), 1))))
.then((ret) => console.log(ret));

=> HTTP/1.1 401 Unauthorized
{
  "errors": [ { "code": "unauthorized", "description": "Unauthorized" } ]
}

=> {
  "errors": [ { "code": "unauthorized", "description": "Unauthorized" } ]
}

=> {
  ref: ref(id = "1", class = ref(id = "magical_creatures", class = ref(id = "classes"))), 
  ts: 1536603599790006, 
  data: {name: "Hen Wen"}
}

=> map[ref:{1 0xc4201a85e0 <nil>} ts:1526946657492696 data:map[name:Hen Wen]]

=> {
  "errors": [ { "code": "unauthorized", "description": "Unauthorized" } ]
}

=> {
  "errors": [ { "code": "unauthorized", "description": "Unauthorized" } ]
}

=> {
  "errors": [ { "code": "unauthorized", "description": "Unauthorized" } ]
}

=> {
  "errors": [ { "code": "unauthorized", "description": "Unauthorized" } ]
}

=> { ref: Ref(id=1, class=Ref(id=magical_creatures, class=Ref(id=classes))),
  ts: 1526675832587944,
  data: { name: 'Hen Wen' } }

Related References

If


If( cond_expr, true_expr, false_expr )

If( cond_expr, true_expr, false_expr )

If( cond_expr, true_expr, false_expr )

If( cond_expr, true_expr, false_expr )

if_expr( cond_expr, true_expr, false_expr )

if_( cond_expr, true_expr, false_expr )

If( cond_expr, true_expr, false_expr )

If( cond_expr, true_expr, false_expr )

Description

The If function evaluates and returns “true_expr” or “false_expr” depending on the value of the “cond” expression. If the “cond” expression evaluates to anything other than a Boolean, If returns an “invalid argument” error.

Parameters

Argument Type Definition and Requirements
cond Boolean Expression The conditional expression to evaluate as true or false.
true_expr Expression The FQL statement or variable to return if “cond” is true.
false_expr Expression The FQL statement or variable to return if “cond” is false.

Returns

The evaluation of either “true_expr” or “false_expr”.

Examples

The query below evaluates the first expression, the conditional expression, and then determines that the conditional expression returns “true”. This causes the second argument, the true expression, to be evaluated and returned. The third argument, the false expression, is never evaluated.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "if": true, "then": "was true", "else": "was false" }'

client.Query(If(true, "was true", "was false"));

System.out.println(
         client.query(
                 If(Value(true), Value("was true"), Value("was false"))
         ).get() );

result, _ := client.Query(f.If(true, "was true", "was false"))

fmt.Println(result)

client.query(If(true, "was true", "was false"))

client.query(q.if_expr(True, "was true", "was false"))

$client.query do
  if_(true, 'was true', 'was false')
end

client.query(If(true, then: "was true", else: "was false"))

client.query(q.If(true, "was true", "was false"))
  .then((ret) => console.log(ret));

=> HTTP/1.1 200 OK
{ "resource": "was true" }

=> "was true"

=> "was true"

=> was true

=> "was true"

=> "was true"

=> "was true"

=> "was true"

=> "was true"

Related References

Lambda


params => expression

Lambda( params, expression )

Lambda( params, expression )

Lambda { params => expression }

lambda_( params, expression )

| params | expression

Lambda( params, expression )

Description

The Lambda function is an anonymous function that performs lazy execution of custom code. It allows you to organize and execute almost any of the Fauna Query Language statements. A Lambda can take zero or more arguments. Lambdas that define multiple parameters use a “params” array to define the arguments. In this case, the items inside the “params” array are the arguments, not the array itself. The “params” array must have the same number of elements as the Lambda function expects, or an “_” (i.e., underscore) argument to drop the extra arguments in the array. Otherwise, it will return an error. The Lambda arguments may be accessed inside the Lambda code using the Var statement.

Parameters

Argument Type Definition and Requirements
params Value or Array A single argument or an array of zero or more arguments.
expression Expressions An expression to be evaluated.

Returns

The evaluation of the expression.

Examples

The query below uses a Map function to provide a single argument to the Lambda. The Lambda takes the argument called “name”, resolves it to the value “Hen ”, and then provides it to the first argument to concatenate with the string “Wen”. The result of “Hen Wen” is then returned.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{
          "map": {
            "lambda": "name",
            "expr": { "concat": [ { "var": "name" }, "Wen" ] }
          },
          "collection": [ "Hen " ]
        }'

client.Query(Map(Arr("Hen "), name => Concat(Arr(name, "Wen"))));

System.out.println(
      client.query(
        Map(
          Arr( Value("Hen ")),
          Lambda(
            Value("name"),
            Concat(Arr(Var("name"), Value("Wen")))
          )
        )
      ).get());

result, _ := client.Query(
    f.Map(
        f.Arr{"Hen "},
        f.Lambda("name", f.Concat(f.Arr{f.Var("name"), "Wen"})),
    ),
)

fmt.Println(result)

client.query(
  Map(Arr("Hen "), Lambda { name => Concat(Arr(name, "Wen")) }))

client.query(
  q.map_expr(q.lambda_("name", q.concat([q.var("name"), "Wen")), ["Hen "]))

$client.query do
  map ['Hen '] do |name|
    concat([name, 'Wen'])
  end
end

client.query(
    Map(
        collection: Arr("Hen "),
        to: { name in Concat(name, "Wen") }
    )
)

client.query(
  q.Map(
    ["Hen "],
    q.Lambda("name", q.Concat([q.Var("name"), "Wen"]))))
.then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{ "resource": [ "Hen Wen" ] }

=> [ "Hen Wen" ]

=> ["Hen Wen"]

=> [Hen Wen]

=> [ "Hen Wen" ]

=> [ "Hen Wen" ]

=> [ "Hen Wen" ]

=> [ "Hen Wen" ]

=> [ 'Hen Wen' ]

The query below passes multiple arguments to a Lambda. The number of values in the array passed into the Lambda and the number of arguments in the Lambda must match exactly. In this example, the Map passes an array with two elements and the Lambda takes an array with two elements. The Lamba resolves the two arguments to their values and then calls the Concat function with the values.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{
          "map": {
            "lambda": [ "f", "l" ],
            "expr": {
              "concat": [ { "var": "f" }, { "var": "l" } ],
              "separator": " "
            }
          },
          "collection": [ [ "Hen", "Wen" ] ]
        }'

client.Query(
  Map(Arr(Arr("Hen", "Wen")), f, l) => Concat(Arr(f, l), " ")));

System.out.println(
      client.query(
        Map(
          Arr(
            Arr(Value("Hen"), Value("Wen"))
          ),
          Lambda(
            Arr(Value("f"),Value("l")),
            Concat(Arr(Var("f"), Var("l")), Value(" "))
          )
        )
      ).get());

result, _ := client.Query(
    f.Map(
        f.Arr{f.Arr{"Hen", "Wen"}},
        f.Lambda(
            f.Arr{"f", "l"},
            f.Concat(
                f.Arr{f.Var("f"), f.Var("l")},
                f.Separator(" "),
            ),
        ),
    ),
)

fmt.Println(result)

client.query(
  Map(
    Arr(Arr("Hen", "Wen")),
    Lambda { (f, l) => Concat(Arr(f, l), " ") }))

client.query(
  q.map_expr(
    lambda f, l: q.concat([f, l], " "),
    [["Hen", "Wen"]]
  ))

$client.query do
  map [['Hen', 'Wen']] do |f, l|
    concat([f, l], ' ')
  end
end

client.query(
    Map(
        collection: Arr(Arr("Hen", "Wen")),
        to: { (f, l) in Concat(f, l, separator: " ") }
    )
)

client.query(
  q.Map(
    [["Hen", "Wen"]],
    q.Lambda(["f", "l"], q.Concat([q.Var("f"), q.Var("l")], q.Value(" ")))))
.then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{ "resource": [ "Hen Wen" ] }

=> [ "Hen Wen" ]

=> ["Hen Wen"]

=> [Hen Wen]

=> [ "Hen Wen" ]

=> [ "Hen Wen" ]

=> [ "Hen Wen" ]

=> [ "Hen Wen" ]

=> [ 'Hen Wen' ]

The query below passes more arguments to the Lambda than the Lambda expects. In this case, the “_” (i.e., underscore) has been provided to the “params” array so that the Lambda function knows to discard the extra arguments. If the “_” had not been provided, this function would have returned an error.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{
          "map": { "lambda": [ "f", "_" ], "expr": { "var": "f" } },
          "collection": [ [ "Hen", "Wen" ] ]
        }'

client.Query(
  Map(Arr(Arr("Hen", "Wen")), Lambda(Arr("f", "_"), Var("f"))));

System.out.println(
      client.query(
        Map(
          Arr(Arr(Value("Hen"), Value("Wen"))),
          Lambda(
             Arr(Value("f"),Value("_")),
             Concat( Arr(Var("f")), Value(" "))
          )
        )
      ).get());

result, _ :=  client.Query(
    f.Map(
        f.Arr{f.Arr{"Hen", "Wen"}},
        f.Lambda(f.Arr{"f", "_"}, f.Var("f")),
    ),
)

fmt.Println(result)

client.query(
  Map(Arr(Arr("Hen", "Wen")), Lambda { (f, _) => f }))

client.query(
  q.map_expr(
    q.lambda_expr(["f", "_"], q.var("f")),
    [["Hen", "Wen"]]
  ))

$client.query do
  map [['Hen', 'Wen']], lambda_expr(['f', '_'], var('f'))
end

client.query(
    Map(
        collection: Arr(Arr("Hen", "Wen")),
        to: Lambda(vars: "f", "_" in: Var("f"))
    )
)

client.query(q.Map([["Hen", "Wen"]], q.Lambda(["f", "_"], q.Var("f"), q.Value(" ")))
  .then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{ "resource": [ "Hen" ] }

=> [ "Hen" ]

=> ["Hen"]

=> [Hen]

=> [ "Hen" ]

=> [ "Hen" ]

=> [ "Hen" ]

=> [ "Hen" ]

=> [ 'Hen' ]

Related References

Let


Let( bindings, in )

Let( bindings, in )

Let( bindings, in )

Let (  binding, in )

let( binding, in)

let( binding, in )

Let( bindings, in )

Let( binding, in )

Description

The Let function binds one or more variables to a single value or expression. When multiple variables are defined, the evaluation is from left to right. Variables which have previously been defined may be used to define future variables. Variables are lexically scoped to the expression passed via the “in” argument. The value of a variable can be referenced with Var(varname) syntax.

Parameters

Argument Type Definition and Requirements
bindings List of pairs The variable or variables to define.
in Expression The expression in which the variables are defined.

Returns

The evaluation of the “in” argument.

Examples

The query below defines two variables to be used by the expression defined by the “in” argument. The first variable “x” contains the value 1 and the second variable “y” contains the value 2. The expression defined by the “in” argument simply returns the value of the variable “x”. The value is accessed by using the Var statement with the associated variable’s name.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "let": { "x": 1, "y": 2 }, "in": { "var": "x" } }'

client.Query(Let(Obj("x", 1, "y", 2), Var("x")));

System.out.println(
         client.query(
               Let( "x", Value(1), "y", Value(2) ).in( Var("x") )
         ).get() );

result, _ := client.Query(f.Let(f.Obj{"x": 1, "y": 2}, f.Var("x")))

fmt.Println(result)

Let(Seq("x" -> 1, "y" -> 2), Var("x"))

client.query(q.let({"x": 1, "y": 2}, q.var("x")))

$client.query do
  let(x: 1, y: 2) do
    x
  end
end

client.query(Let(bindings: [ x: 1, y: 2 ], in: Var("x")))

client.query(q.Let({ x: 1, y: 2 }, q.Var("x")))
  .then((ret) => console.log(ret));

=> HTTP/1.1 200 OK
{ "resource": 1 }

=> 1

=> 1

=> 1

=> 1

=> 1

=> 1

=> 1

=> 1

Related References

Var


Var( name )

Var( name )

Var( name )

Var (  name )

let name

let( name )

Var( name )

Var( name )

Description

The Var statement evaluates and returns the value stored in a named variable. The Var statement can only be used inside other statements, such as Let or Lambda.

Parameters

Argument Type Definition and Requirements
name String The name of the variable.

Returns

The value stored in the named variable.

Examples

The query below defines two variables in a Let statement. The first variable “x” contains the value 1 and the second variable “y” contains the value 2. When the simple “in” expression is executed, it returns the value stored in the variable “x”.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "let": { "x": 1, "y": 2 }, "in": { "var": "x" } }'

client.Query(Let(Obj("x", 1, "y", 2), Var("x")));

System.out.println(
         client.query(
               Let( "x", Value(1), "y", Value(2) ).in( Var("x") )
         ).get() );

result, _ := client.Query(f.Let(f.Obj{"x": 1, "y": 2}, f.Var("x")))

fmt.Println(result)

Let(Seq("x" -> 1, "y" -> 2), Var("x"))

client.query(q.let({"x": 1, "y": 2}, q.var("x")))

$client.query do
  let(x: 1, y: 2) do
    x
  end
end

client.query(Let(bindings: [ x: 1, y: 2 ], in: Var("x")))

client.query(q.Let({ x: 1, y: 2 }, q.Var("x")))
  .then((ret) => console.log(ret));

=> HTTP/1.1 200 OK
{ "resource": 1 }

=> 1

=> 1

=> 1

=> 1

=> 1

=> 1

=> 1

=> 1

Related References

Let Statement

Collections

A collection is an ordered group of values. These values are stored in an Array or in a Page which is an object that contains an array as one of its elements. When page’s are passed to a collection function, only the array element of the page is examined or transformed. Other elements of the page are passed directly through to the output.

Append


Append( elems, base )

Append( elems, base )

Append( elems, base )

Append( elems, base )

append( elems, base )

append elems, base

Append( elems, base )

Append( elems, base )

Description

The Append function creates a new array that is the result of combining the base Array followed by the “elems”. This is a specialized function and will only work with collections of type array.

Parameters

Argument Type Definition and Requirements
base Array The base array.
elems Value or Array The elements to add to the end of the base array.

Returns

A new array containing both the “base” array followed by the “elems”.

Examples

A new array containing the array “base”, 1 2 3, followed by the “elems” values, 4 5 6.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "append": [ 4, 5, 6 ], "collection": [ 1, 2, 3 ] }'

client.Query(Append(Arr(4, 5, 6), Arr(1, 2, 3)));

System.out.println(
         client.query(
                 Append(
                         Arr(Value(4), Value(5), Value(6)),
                         Arr(Value(1), Value(2), Value(3))
                 )
         ).get());

result, _ := client.Query(f.Append(f.Arr{4, 5, 6}, f.Arr{1, 2, 3}))

fmt.Println(result)

client.query(Append(Arr(4, 5, 6), Arr(1, 2, 3)))

client.query(q.append([4, 5, 6], [1, 2, 3]))

$client.query do
  append [4, 5, 6], [1, 2, 3]
end

client.query(
    Append(elements: Arr(4, 5, 6), to: Arr(1, 2, 3))
)

client.query(q.Append([4, 5, 6], [1, 2, 3]))
  .then((ret) => console.log(ret));

=> HTTP/1.1 200 OK
{ "resource": [ 1, 2, 3, 4, 5, 6 ] }

=> [ 1, 2, 3, 4, 5, 6 ]

=> [1, 2, 3, 4, 5, 6]

=> [1 2 3 4 5 6]

=> [ 1, 2, 3, 4, 5, 6 ]

=> [ 1, 2, 3, 4, 5, 6 ]

=> [ 1, 2, 3, 4, 5, 6 ]

=> [ 1, 2, 3, 4, 5, 6 ]

=> [ 1, 2, 3, 4, 5, 6 ]

Related References

Drop


Drop( num, collection )

Drop( num, collection )

Drop( num, collection )

Drop( num, collection )

drop( num, collection )

drop num, collection

Drop( num, collection )

Drop( num, collection )

Description

The Drop function returns a new collection of the same type that contains the remaining elements, after “num” have been removed from the head of the collection. If “num” is zero or negative, all elements of the collection are returned unmodified.

When applied to a collection of type page, the returned page’s “before” cursor is adjusted to exclude the dropped elements. As special cases:

  • If “num” is negative, “before” does not change.
  • Otherwise if all elements from the original page were dropped (including the case where the page was already empty), “before” will be set to same value as the original page’s “after”.

Parameters

Argument Type Definition and Requirements
collection Collection The drop operations will be performed on this collection.
num Integer The number of elements to extract from the beginning of the collection.

Returns

A new collection of the same type omitting the first “num” elements.

Examples

The query below creates a new collection of type Array containing a copy of the last element of the collection passed into the function.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "drop": 2, "collection": [ 1, 2, 3 ] }'

client.Query(Drop(2, Arr(1, 2, 3)));

System.out.println(
         client.query(
                 Drop(Value(2), Arr(Value(1), Value(2), Value(3)))
         ).get());

result, _ := client.Query(f.Drop(2, f.Arr{1, 2, 3}))

fmt.Println(result)

client.query(Drop(2, Arr(1, 2, 3)))

client.query(q.drop(2, [1, 2, 3]))

$client.query do
  drop 2, [1, 2, 3]
end

client.query(Drop(count: 2, from: Arr(1, 2, 3)))

client.query(q.Drop(2, [1, 2, 3]))
  .then((ret) => console.log(ret));

=> HTTP/1.1 200 OK
{ "resource": [ 3 ] }

=> [ 3 ]

=> [3]

=> [3]

=> [ 3 ]

=> [ 3 ]

=> [ 3 ]

=> [ 3 ]

=> [ 3 ]

Related References

Filter


Filter( collection, lambda )

Filter( collection, lambda )

Filter( collection, lambda )

Filter( collection, lambda )

filter_expr( lambda, collection )

filter collection lambda

Filter( collection, lambda )

Filter( collection, lambda )

Description

The Filter function applies the lambda to each member of the collection and returns a new collection of the same type containing only those elements for which the lambda returns true. Providing a lambda which does not return a Boolean results in an “invalid argument” error. If a Page is passed, its decorated fields are preserved in the result.

Parameters

Argument Type Definition and Requirements
collection Collection The target collection over which the lambda will iterate/operate.
lambda Lambda The anonymous function to be executed which must return a boolean.

Returns

A new collection with the elements of the collection which caused lambda to return true.

Examples

The query below iterates over the collection containing the values 1, 2, 3 executing the lambda for each value. The lambda returns true if the Modulo 2 of the value is 0 else it returns false.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{
          "filter": {
            "lambda": "i",
            "expr": { "equals": [ 0, { "modulo": [ { "var": "i" }, 2 ] } ] }
          },
          "collection": [ 1, 2, 3 ]
        }'

client.Query(
  Filter(Arr(1, 2, 3), i => EqualsFn(0, Modulo(i, 2))));

System.out.println(
  client.query(
    Filter(
      Arr(Value(1), Value(2), Value(3)),
      Lambda(
            Value("i"),
            Equals(Value(0), Modulo(Var("i"), Value(2)))
      )
    )
  ).get());

result, _ := client.Query(
    f.Filter(
        f.Arr{1, 2, 3},
        f.Lambda("i", f.Equals(0, f.Modulo(f.Var("i"), 2))),
    ),
)

fmt.Println(result)

client.query(
  Filter(Arr(1, 2, 3), Lambda { i => Equals(0, Modulo(i, 2)) }))

client.query(
  q.filter_expr(
    lambda i: q.equals(0, q.modulo(i, 2)),
    [1, 2, 3]
  ))

$client.query do
  filter [1, 2, 3] do |i|
    equals(0, modulo(i, 2))
  end
end

client.query(
    Filter(
        collection: Arr(1, 2, 3),
        with: { i in Equals(0, Modulo(i, 2)) }
    )
)

client.query(
  q.Filter([1, 2, 3], q.Lambda("i", q.Equals(0, q.Modulo(q.Var("i"), 2)))))
.then((ret) => console.log(ret));

=> HTTP/1.1 200 OK
{ "resource": [ 2 ] }

=> [ 2 ]

=> [2]

=> [2]

=> [ 2 ]

=> [ 2 ]

=> [ 2 ]

=> [ 2 ]

=> [ 2 ]

Related References

Foreach


Foreach( collection, lambda )

Foreach( collection, lambda )

Foreach( collection, lambda )

Foreach( collection, lambda )

foreach( lambda, collection )

foreach collection, lambda

Foreach( collection, lambda )

Foreach( collection, lambda )

Description

The Foreach function applies the Lambda serially to each member of a “collection”, and returns the original collection. The Foreach function is very useful when the original collection does not need to be modified, but a side effect is required for every value in a collection. Later invocations of the Lambda can see the side effects of earlier invocations of the Lambda.

Parameters

Argument Type Definition and Requirements
collection Collection The target collection over which the lambda will iterate/operate.
lambda Lambda The anonymous function to be executed.

Returns

The original collection without any modifications.

Examples

The query below iterates over the results returned by the Paginate function executing the Lambda for each value in the result collection. The result collection contains an array of references, each reference’s instance is updated by the lambda.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{
          "foreach": {
            "lambda": "spell",
            "expr": {
              "update": { "var": "spell" },
              "params": {
                "object": {
                  "data": {
                    "object": {
                      "spellbook": { "@ref": "classes/spellbooks/181388642139243008" }
                    }
                  }
                }
              }
            }
          },
          "collection": {
            "paginate": {
              "match": { "index": "spells_by_element" },
              "terms": "fire"
            }
          }
        }'

client.Query(
  Foreach(
    Paginate(Match(Index("spells_by_element"), "fire")),
    spell => Update(
      spell,
      Obj(
        "data", Obj(
          "spellbook", Ref("classes/spellbooks/181388642139243008")
        )
      ))));

System.out.println(
      client.query(
          Foreach(
             Paginate(
                Match(Index(Value("spells_by_element")), Value("fire"))
             ),
             Lambda(
                Value("spell"),
                Update(
                   Var("spell"),
                   Obj("data",
                      Obj("spellbook",
                      Ref(Class(Value("spellbooks")),Value(181388642139243008L)))
                   )
                )
             )
         )
      ).get()
);

result, _ := client.Query(
    f.Foreach(
        f.Paginate(
            f.MatchTerm(f.Index("spells_by_element"), "fire"),
        ),
        f.Lambda(
            "spell",
            f.Update(
                f.Var("spell"),
                f.Obj{
                    "data": f.Obj{
                        "spellbook": f.RefClass(f.Class("spellbooks"), "181388642139243008"),
                    },
                },
            ),
        ),
    ),
)

fmt.Println(result)

client.query(
  Foreach(
    Paginate(Match(Index("spells_by_element"), "fire")),
    Lambda { spell =>
      Update(
        spell,
        Obj(
          "data" -> Obj(
            "spellbook" -> Ref("classes/spellbooks/181388642139243008")
          )
        ))
    }))

client.query(
  q.foreach(
    lambda spell: q.update(
      spell,
      {
        "data": {
          "spellbook": Ref("classes/spellbooks/181388642139243008")
        }
      }
    ),
    q.paginate(q.match(q.index("spells_by_element"), "fire"))
  ))

$client.query do
  foreach paginate(match(index('spells_by_element'), 'fire')) do |spell|
    update(spell,
           data: { spellbook: ref('classes/spellbooks/181388642139243008') })
  end
end

client.query(
    Foreach(
        collection: Paginate(
            Match(
                index: Index("spells_by_element"),
                terms: "fire"
            )
        ),
        in: { spell in
            Update(
                ref: spell,
                to: Obj(
                    "data" => Obj(
                        "spellbook" => Ref("classes/spellbooks/181388642139243008")
                    )
                )
            )
        }
    )
)

client.query(
  q.Foreach(
    q.Paginate(q.Match(q.Index("spells_by_element"), "fire")),
    q.Lambda("spell",
      q.Update(q.Var("spell"), { data: { spellbook: q.Ref(q.Class("spellbooks"), 181388642139243008) } }))))
.then((ret) => console.log(ret));

=> HTTP/1.1 200 OK
{
  "resource": {
    "data": [
      { "@ref": "classes/spells/181388642046968320" },
      { "@ref": "classes/spells/181388642071085568" }
    ]
  }
}

=> {
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/spells/181388642071085568" }
  ]
}

=> {
  data: [
    ref(id = "181388642046968320", class = ref(id = "spells", class = ref(id = "classes"))),
    ref(id = "181388642071085568", class = ref(id = "spells", class = ref(id = "classes")))
  ]
}

=> map[data:[{181388642046968320 0xc4201c3720 <nil>} {181388642071085568 0xc4201c3940 <nil>}]]

=> {
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/spells/181388642071085568" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/spells/181388642071085568" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/spells/181388642071085568" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/spells/181388642071085568" }
  ]
}

=> { data:
   [ Ref(id=181388642046968320, class=Ref(id=spells, class=Ref(id=classes))),
     Ref(id=181388642071085568, class=Ref(id=spells, class=Ref(id=classes))) ] }

Related References

isEmpty


IsEmpty( collection )

IsEmpty( collection )

IsEmpty( collection )

IsEmpty( collection )

is_empty( collection )

is_empty( collection )

IsEmpty( collection )

IsEmpty( collection )

Description

The IsEmpty function returns true only if there are no elements in the collection.

Parameters

Argument Type Definition and Requirements
collection Collection A collection which is checked for the non-existance of elements.

Returns

Returns a boolean

Examples

The query below executes an array of independent IsEmpty operations and returns the results in an array. The result array position matches the execution array position. The first IsEmpty operation operates on an empty array and places the result of true in the top position in the result array. The second IsEmpty operation operates on an array with a single value of 1 and places the result of false in the second position in the result array. The third IsEmpty operation operates on an array with a two values and places the result of false in the third position in the result array.


System.out.println(
  client.query(
    Arr(
        IsEmpty( Arr()),
        IsEmpty( Arr(Value(1))),
        IsEmpty( Arr(Value(1), Value(2), Value(3)))
    )
  ).get());

=> [true, false, false]

Related References

isNonEmpty


IsNonEmpty( collection )

IsNonEmpty( collection )

IsNonEmpty( collection )

IsNonEmpty( collection )

is_nonempty( collection )

is_nonempty( collection )

IsNonEmpty( collection )

IsNonEmpty( collection )

Description

The isNonEmpty function returns true only if there is one or more elements in the collection.

Parameters

Argument Type Definition and Requirements
collection Collection A collection which is checked for the existance of elements.

Returns

Returns a boolean

Examples

The query below executes an array of independent IsNonEmpty operations and returns the results in an array. The result array position matches the execution array position. The first IsNonEmpty operation operates on an empty array and places the result of false in the top position in the result array. The second IsNonEmpty operation operates on an array with a single value of 1 and places the result of true in the second position in the result array. The third IsNonEmpty operation operates on an array with two values and places the result of true in the third position in the result array.


System.out.println(
  client.query(
    Arr(
        IsNonEmpty( Arr()),
        IsNonEmpty( Arr(Value(1))),
        IsNonEmpty( Arr(Value(1), Value(2), Value(3)))
    )
  ).get());

=> [false, true, true]

Related References

Map


( collection, lambda )

Map( collection, lambda )

Map( collection, lambda )

Map( collection, lambda )

map_expr( lambda, collection )

map collection  lambda

Map( collection, lambda )

Map( collection, lambda )

Description

The Map function applies a lambda serially to each member of the “collection” and returns the results of each application in a new collection of the same type. Later invocations of the Lambda function can see the results of earlier invocations.

Parameters

Argument Type Definition and Requirements
collection Collection The target collection over which the lambda will iterate/operate.
lambda Lambda The anonymous function to be executed.

Returns

A new collection with the results of the Lambda for the given collection.

Examples

The query below has a Lambda which takes one variable “x” and adds 1 and then returns the value. This Lambda is executed once for each value in the collection. These values are 1, 2, 3.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{
          "map": { "lambda": "x", "expr": { "add": [ { "var": "x" }, 1 ] } },
          "collection": [ 1, 2, 3 ]
        }'

client.Query(Map(Arr(1, 2, 3), x => Add(x, 1)));

System.out.println(
  client.query(
    Map(
       Arr(Value(1), Value(2), Value(3)),
       Lambda(Value("x"), Add(Var("x"), Value(1)))
    )
  ).get());

result, _ := client.Query(
    f.Map(f.Arr{1, 2, 3}, f.Lambda("x", f.Add(f.Var("x"), 1))),
)

fmt.Println(result)

client.query(Map(Arr(1, 2, 3), Lambda { x => Add(x, 1) }))

client.query(q.map_expr(lambda x: q.add(x, 1), [1, 2, 3]))

$client.query do
  map [1, 2, 3] do |x|
    add(x, 1)
  end
end

client.query(
    Map(collection: Arr(1, 2, 3), to: { x in Add(x, 1) })
)

client.query(
  q.Map([1, 2, 3], q.Lambda("x", q.Add(q.Var("x"), 1))))
.then((ret) => console.log(ret));

=> HTTP/1.1 200 OK
{ "resource": [ 2, 3, 4 ] }

=> [ 2, 3, 4 ]

=> [2, 3, 4]

=> [2 3 4]

=> [ 2, 3, 4 ]

=> [ 2, 3, 4 ]

=> [ 2, 3, 4 ]

=> [ 2, 3, 4 ]

=> [ 2, 3, 4 ]

Related References

Take


Take( num, collection )

Take( num, collection )

Take( num, collection )

Take( num, collection )

take( num, collection )

take num, collection

Take( num, collection )

Take( num, collection )

Description

The Take function returns a new collection of the same type that contains “num” elements from the head of the collection. If “num” is zero or negative, the resulting collection is empty.

When applied to a collection which is of type page, the returned page’s “after” cursor is adjusted to only cover the taken elements. As special cases:

  • If “num” is negative, “after” will be set to the same value as the original page’s “before”.
  • If all elements from the original page were taken, “after” does not change.

Parameters

Argument Type Definition and Requirements
collection Collection The take operations will be performed on this collection.
num Integer The number of elements to extract from the beginning of the collection.

Returns

A new collection of the same type with the first “num” elements.

Examples

The query below creates a new array collection containing copies of the first two elements of the collection’s argument.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "take": 2, "collection": [ 1, 2, 3 ] }'

client.Query(Take(2, Arr(1, 2, 3)));

System.out.println(
        client.query(
                Take(Value(2), Arr(Value(1), Value(2), Value(3))
                )
        ).get());

result, _ := client.Query(f.Take(2, f.Arr{1, 2, 3}))

fmt.Println(result)

client.query(Take(2, Arr(1, 2, 3)))

client.query(q.take(2, [1, 2, 3]))

$client.query do
  take 2, [1, 2, 3]
end

client.query(Take(count: 2, from: Arr(1, 2, 3)))

client.query(q.Take(2, [1, 2, 3]))
  .then((ret) => console.log(ret));

=> HTTP/1.1 200 OK
{ "resource": [ 1, 2 ] }

=> [ 1, 2 ]

=> [1, 2]

=> [1 2]

=> [ 1, 2 ]

=> [ 1, 2 ]

=> [ 1, 2 ]

=> [ 1, 2 ]

=> [ 1, 2 ]

Related References

Prepend


Prepend( elems, base )

Prepend( elems, base )

Prepend( elems, base )

Prepend( elems, base )

prepend( elems, base )

prepend elems, base

Prepend( elems, base )

Prepend( elems, base )

Description

The Prepend function creates a new array that is the result of combining the “elems” followed by the “base” Array. This function will only work with collections of type array.

Parameters

Argument Type Definition and Requirements
base Array The base array.
elems Value or Array The elements to add to the beginning of the base array.

Returns

A new array containing both elems followed by the collection.

Examples

A new array containing the array “elems”, 1 2 3, followed by the “collection” values, 4 5 6.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "prepend": [ 1, 2, 3 ], "collection": [ 4, 5, 6 ] }'

client.Query(Prepend(Arr(1, 2, 3), Arr(4, 5, 6)));

System.out.println(
        client.query(
                Prepend(
                        Arr(Value(1), Value(2), Value(3)),
                        Arr(Value(4), Value(5), Value(6))
                )
        ).get());

result, _ := client.Query(f.Prepend(f.Arr{1, 2, 3}, f.Arr{4, 5, 6}))

fmt.Println(result)

client.query(Prepend(Arr(1, 2, 3), Arr(4, 5, 6)))

client.query(q.prepend([1, 2, 3], [4, 5, 6]))

$client.query do
  prepend [1, 2, 3], [4, 5, 6]
end

client.query(
    Prepend(elements: Arr(1, 2, 3), to: Arr(4, 5, 6))
)

client.query(q.Prepend([1, 2, 3], [4, 5, 6]))
  .then((ret) => console.log(ret));

=> HTTP/1.1 200 OK
{ "resource": [ 1, 2, 3, 4, 5, 6 ] }

=> [ 1, 2, 3, 4, 5, 6 ]

=> [1, 2, 3, 4, 5, 6]

=> [1 2 3 4 5 6]

=> [ 1, 2, 3, 4, 5, 6 ]

=> [ 1, 2, 3, 4, 5, 6 ]

=> [ 1, 2, 3, 4, 5, 6 ]

=> [ 1, 2, 3, 4, 5, 6 ]

=> [ 1, 2, 3, 4, 5, 6 ]

Related References

Conversion Functions

ToDate


ToDate( value )

ToDate( value )

ToDate( value )

ToDate( value )

ToDate( value )

ToDate( value )

Description

The ToDate function converts a value to a date type, if possible.

Attempting to convert a value to a date which has no date representation will result in an “invalid argument” error.

Parameters

Argument Type Definition and Requirements
value Any The value to attempt to convert to a date type.

Returns

A date type of value.

Examples

The query below converts the string “2018-06-06” to a date.


System.out.println(
        client.query(
          ToDate(Value("2018-06-06"))
        ).get());

result, _ := client.Query(ToDate("2018-06-06"))
fmt.PrintLn(result)

client.query(q.ToDate("2018-06-06")).then((ret) => console.log(ret))

=> 2018-06-06

=> {0 63663840000 <nil>}

=> FaunaDate { value: '2018-06-06' }

Related References

ToNumber


ToNumber( value )

ToNumber( value )

ToNumber( value )

ToNumber( value )

ToNumber( value )

ToNumber( value )

Description

The ToNumber function converts a value to a numeric literal, if possible.

Attempting to convert a value to a number which has no numeric representation will result in an “invalid argument” error.

Parameters

Argument Type Definition and Requirements
value Any The value to attempt to convert to a number type.

Returns

A number type of value.

Examples

The query below executes an array of independent ToNumber operations and returns the results in an array. The result array position matches the execution array position. The first operation converts a floating point literal to a number. The second operation takes an integer literal and converts it to a number. The last operation converts a string to a number.


System.out.println(
        client.query(Arr(
                ToNumber(Value(1234.5678)),
                ToNumber(Value(1234)),
                ToNumber(Value("123"))
        )).get());

result, _ := client.Query(f.Arr{
    f.ToNumber(1234.5678),
    f.ToNumber(1234),
    f.ToNumber("123")})
fmt.Println(result)

client.query([
    q.ToNumber(1234.5678),
    q.ToNumber(1234),
    q.ToNumber("123")
]).then((ret) => console.log(ret))

=> [1234.5678, 1234, 123]

=> [1234.5678 1234 123]

=> [ 1234.5678, 1234, 123 ]

Related References

ToString


toStringExpr( value )

ToString( value )

ToString( value )

ToString( value )

ToString( value )

ToString( value )

Description

The ToString function converts a value to a string type, if possible.

Attempting to convert a value to a string which has no string representation will result in an “invalid argument” error.

Parameters

Argument Type Definition and Requirements
value Any The value to attempt to convert to a string type.

Returns

A string type of value.

Examples

The query below executes an array of independent ToString operations and returns the results in an array. The result array position matches the execution array position. The first operation converts a floating point literal to a string. The second operation takes an integer literal and converts it to a string. The third operation converts a date to a string.


client.Query(
  Arr(ToStringExpr(1234.5678),
      ToStringExpr(true),
      ToStringExpr(Date("2018-06-06")),
      ToStringExpr(null),
      ToStringExpr(Time("2015-02-20T06:30:00Z"))));

System.out.println(
        client.query(Arr(
                ToString(Value(1234.5678)),
                ToString(Value(true)),
                ToString(Date("2018-06-06")),
                ToString(null),
                ToString(Time("2015-02-20T06:30:00Z"))
        )).get());

result, _ := client.Query(
    f.Arr(f.ToString(1234.5678),
          f.ToString(true),
          f.ToString(f.Date("2018-06-06")),
          f.ToString(f.Null()),
          f.ToString(f.Time("2015-02-20T06:30:00Z"))))
fmt.Println(result)

client.query([
        q.ToString(1234.5678),
        q.ToString(true),
        q.ToString(q.Date("2018-06-06")),
        q.ToString(null),
        q.ToString(q.Time("2015-02-20T06:30:00Z"))
    ]).then((ret) => console.log(ret))

=> ["1234.5678", "true", "2018-06-06", "null", "2015-02-20T06:30:00Z"]

=> [1234.5678 true 2018-06-06 null 2015-02-20T06:30:00Z]

=> [ '1234.5678', 'true', '2018-06-06', 'null', '2015-02-20T06:30:00Z' ]

Related References

ToTime


ToTime( value )

ToTime( value )

ToTime( value )

ToTime( value )

ToTime( value )

=> 2015-02-20T06:30:00Z

=> {0 63560010600 <nil>}

Description

The ToTime function converts a value to a timestamp type, if possible.

Attempting to convert a value to a timestamp which has no timestamp representation will result in an “invalid argument” error.

Parameters

Argument Type Definition and Requirements
value Any The value to attempt to convert to a timestamp type.

Returns

A timestamp type of value.

Examples

The query below converts the string “2015-02-20T06:30:00Z” to a timestamp.


System.out.println(
        client.query(
                ToTime(Value("2015-02-20T06:30:00Z"))
        ).get());

result, _ := client.Query(ToTime("2015-02-20T06:30:00Z"))
fmt.Println(result)

client.query(q.ToTime("2015-02-20T06:30:00Z")).then((ret) => console.log(ret))

=> 2015-02-20T06:30:00Z

=> {0 63560010600 <nil>}

Related References

Read Functions

Get


Get( ref, [ts] )

Get( ref, [ts] )

Get( ref, [ts] )

Get( ref, [ts] )

get( ref, [ts] )

get ref [ts]

Get( ref, [ts] )

Get( ref, [ts] )

Description

The get function retrieves a single instance identified by ref. An optional timestamp(ts) can be provided to retrieve the instance which existed at the specific date and time. If the timestamp is omitted the default is the current time.

Errors

  • If the instance does not exist, an “instance not found” error will be returned. Use the exists predicate to avoid “instance not found” errors.
  • If the client does not have read permission for the instance, a “permission denied” error will be returned.

Parameter

Argument Type Definition and Requirements
ref Reference An instance reference uniquely identifies an instance
ts Integer or time value Optional - Return the instance at the specified point in time (number of UNIX microseconds or time value). The default is the current time.

Returns

An instance object containing both the instance data and metadata described below.

Field Name Field Type Definition and Requirements
ref Reference The reference identifies the instance retrieved.
data Object The instance data retrieved at the location pointed to by ref.
ts Long The timestamp associated with the creation of the instance.

Examples

The query below retrieves an instance by providing a reference to the Class “spells” at a specific id.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "get": { "@ref": "classes/spells/181388642046968320" } }'

client.Query(Get(Ref("classes/spells/181388642046968320")));

System.out.println(
      client.query(
              Get(Ref(
                      Class("spells"),
                      Value(181388642046968320L)
                      )
              )
      ).get()); 

result, _ := client.Query(f.Get(f.RefClass(f.Class("spells"), "181388642046968320")))

fmt.Println(result)

client.query(Get(Ref("classes/spells/181388642046968320")))

client.query(q.get(Ref("classes/spells/181388642046968320")))

$client.query do
  get ref('classes/spells/181388642046968320')
end

client.query(Get(Ref("classes/spells/181388642046968320")))

client.query(q.Get(q.Ref(q.Class("spells"), 181388642046968320)))
  .then((ret) => console.log(ret));

=> HTTP/1.1 200 OK
{
  "resource": {
    "ref": { "@ref": "classes/spells/181388642046968320" },
    "class": { "@ref": "classes/spells" },
    "ts": 1509244539547758,
    "data": {
      "name": "Fire Beak",
      "element": [ "air", "fire" ],
      "spellbook": { "@ref": "classes/spellbooks/181388642139243008" }
    }
  }
}

=> {
  "ref": { "@ref": "classes/spells/181388642046968320" },
  "class": { "@ref": "classes/spells" },
  "ts": 1509244539547758,
  "data": {
    "name": "Fire Beak",
    "element": [ "air", "fire" ],
    "spellbook": { "@ref": "classes/spellbooks/181388642139243008" }
  }
}

=> {
  ref: ref(id = "181388642046968320", class = ref(id = "spells", class = ref(id = "classes"))), 
  ts: 1536604020492774, 
  data: {
    name: "Fire Beak", 
    element: ["air", "fire"], 
    spellbooks: ref(id = "181388642139243008", class = ref(id = "spellbooks", class = ref(id = "classes")))
  }
}

=> map[ref:{181388642046968320 0xc4201c7440 <nil>} ts:1509244539547758 data:map[element:[air fire] name:Fire Beak spellbook:{181388642139243008 0xc4201c77c0 <nil>}]]

=> {
  "ref": { "@ref": "classes/spells/181388642046968320" },
  "class": { "@ref": "classes/spells" },
  "ts": 1509244539547758,
  "data": {
    "name": "Fire Beak",
    "element": [ "air", "fire" ],
    "spellbook": { "@ref": "classes/spellbooks/181388642139243008" }
  }
}

=> {
  "ref": { "@ref": "classes/spells/181388642046968320" },
  "class": { "@ref": "classes/spells" },
  "ts": 1509244539547758,
  "data": {
    "name": "Fire Beak",
    "element": [ "air", "fire" ],
    "spellbook": { "@ref": "classes/spellbooks/181388642139243008" }
  }
}

=> {
  "ref": { "@ref": "classes/spells/181388642046968320" },
  "class": { "@ref": "classes/spells" },
  "ts": 1509244539547758,
  "data": {
    "name": "Fire Beak",
    "element": [ "air", "fire" ],
    "spellbook": { "@ref": "classes/spellbooks/181388642139243008" }
  }
}

=> {
  "ref": { "@ref": "classes/spells/181388642046968320" },
  "class": { "@ref": "classes/spells" },
  "ts": 1509244539547758,
  "data": {
    "name": "Fire Beak",
    "element": [ "air", "fire" ],
    "spellbook": { "@ref": "classes/spellbooks/181388642139243008" }
  }
}

=> { ref: Ref(id=181388642046968320, class=Ref(id=spells, class=Ref(id=classes))),
  ts: 1526677786695156,
  data:
   { name: "Fire Beak",
     element: [ "air", "fire" ],
     spellbook: Ref(id=181388642139243008, class=Ref(id=spellbooks, class=Ref(id=classes))) } }

To retrieve multiple references in a single operation, utilize the array operator to group and return multiple instance records. The example below returns three different idenitifers from the spells class in a single database operation. This saves network bandwidth and processing by grouping several requests for data into the same operation.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '[
          { "get": { "@ref": "classes/spells/181388642046968320" } },
          { "get": { "@ref": "classes/spells/181388642071085568" } },
          { "get": { "@ref": "classes/spells/181388642088911360" } }
        ]'

client.Query(
  Arr(
    Get(Ref("classes/spells/181388642046968320")),
    Get(Ref("classes/spells/181388642071085568")),
    Get(Ref("classes/spells/181388642088911360"))
  ));

System.out.println(
      client.query(
          Arr(
              Get(Ref(Class("spells"),Value(181388642046968320L))),
              Get(Ref(Class("spells"),Value(181388642071085568L))),
              Get(Ref(Class("spells"),Value(181388642088911360L)))
          )
      ).get());

result, _ := client.Query(
    f.Arr{
        f.Get(f.RefClass(f.Class("spells"), "181388642046968320")),
        f.Get(f.RefClass(f.Class("spells"), "181388642071085568")),
        f.Get(f.RefClass(f.Class("spells"), "181388642088911360")),
    },
)

fmt.Println(result)

client.query(
  Arr(
    Get(Ref("classes/spells/181388642046968320")),
    Get(Ref("classes/spells/181388642071085568")),
    Get(Ref("classes/spells/181388642088911360"))
  ))

client.query(
  [
    q.get(Ref("classes/spells/181388642046968320")),
    q.get(Ref("classes/spells/181388642071085568")),
    q.get(Ref("classes/spells/181388642088911360"))
  ])

$client.query do
  [
    get(ref('classes/spells/181388642046968320')),
    get(ref('classes/spells/181388642071085568')),
    get(ref('classes/spells/181388642088911360'))
  ]
end

client.query(
    Arr(
        Get(Ref("classes/spells/181388642046968320")),
        Get(Ref("classes/spells/181388642071085568")),
        Get(Ref("classes/spells/181388642088911360"))
    )
)

client.query([
  q.Get(q.Ref(q.Class("spells"), 181388642046968320)),
  q.Get(q.Ref(q.Class("spells"), 181388642071085568)),
  q.Get(q.Ref(q.Class("spells"), 181388642088911360))
]).then((ret) => console.log(ret));

=> HTTP/1.1 200 OK
{
  "resource": [
    {
      "ref": { "@ref": "classes/spells/181388642046968320" },
      "class": { "@ref": "classes/spells" },
      "ts": 1509244539547758,
      "data": {
        "name": "Fire Beak",
        "element": [ "air", "fire" ],
        "spellbook": { "@ref": "classes/spellbooks/181388642139243008" }
      }
    },
    {
      "ref": { "@ref": "classes/spells/181388642071085568" },
      "class": { "@ref": "classes/spells" },
      "ts": 1509244539547758,
      "data": {
        "name": "Water Dragon's Claw",
        "element": [ "water", "fire" ],
        "spellbook": { "@ref": "classes/spellbooks/181388642139243008" }
      }
    },
    {
      "ref": { "@ref": "classes/spells/181388642088911360" },
      "class": { "@ref": "classes/spells" },
      "ts": 1509244539235128,
      "data": {
        "name": "Hippo's Wallow",
        "element": [ "water", "earth" ]
      }
    }
  ]
}

=> [
  {
    "ref": { "@ref": "classes/spells/181388642046968320" },
    "class": { "@ref": "classes/spells" },
    "ts": 1509244539547758,
    "data": {
      "name": "Fire Beak",
      "element": [ "air", "fire" ],
      "spellbook": { "@ref": "classes/spellbooks/181388642139243008" }
    }
  },
  {
    "ref": { "@ref": "classes/spells/181388642071085568" },
    "class": { "@ref": "classes/spells" },
    "ts": 1509244539547758,
    "data": {
      "name": "Water Dragon's Claw",
      "element": [ "water", "fire" ],
      "spellbook": { "@ref": "classes/spellbooks/181388642139243008" }
    }
  },
  {
    "ref": { "@ref": "classes/spells/181388642088911360" },
    "class": { "@ref": "classes/spells" },
    "ts": 1509244539235128,
    "data": {
      "name": "Hippo's Wallow",
      "element": [ "water", "earth" ]
    }
  }
]

=> [
   {
     ref: ref(id = "181388642046968320", class = ref(id = "spells", class = ref(id = "classes"))), 
     ts: 1536604020492774, 
     data: {
       name: "Fire Beak", 
       element: ["air", "fire"], 
       spellbooks: ref(id = "181388642139243008", class = ref(id = "spellbooks", class = ref(id = "classes")))
     }
   },
   {
     ref: ref(id = "181388642071085568", class = ref(id = "spells", class = ref(id = "classes"))), 
     ts: 1536604020513444, 
     data: {
       name: "Water Dragon's Claw", 
       element: ["water", "fire"], 
       spellbooks: ref(id = "181388642139243008", class = ref(id = "spellbooks", class = ref(id = "classes")))
     }
   },
   {
     ref: ref(id = "181388642088911360", class = ref(id = "spells", class = ref(id = "classes"))), 
     ts: 1536604020270318, 
     data: {
       name: "Hippo's Wallow", 
       element: ["water", "earth"]
     }
   }
 ]

=> [
  map[ref:{181388642046968320 0xc4201d6f20 <nil>} ts:1509244539547758 data:map[element:[air fire] name:Fire Beak spellbook:{181388642139243008 0xc4201d72a0 <nil>}]]
  map[ref:{181388642071085568 0xc4201d74e0 <nil>} ts:1509244539547758 data:map[element:[water fire] name:Water Dragon's Claw spellbook:{181388642139243008 0xc4201d7860 <nil>}]]
  map[ref:{181388642088911360 0xc4201d7ac0 <nil>} ts:1509244539235128 data:map[element:[water earth] name:Hippo's Wallow]]
]

=> [
  {
    "ref": { "@ref": "classes/spells/181388642046968320" },
    "class": { "@ref": "classes/spells" },
    "ts": 1509244539547758,
    "data": {
      "name": "Fire Beak",
      "element": [ "air", "fire" ],
      "spellbook": { "@ref": "classes/spellbooks/181388642139243008" }
    }
  },
  {
    "ref": { "@ref": "classes/spells/181388642071085568" },
    "class": { "@ref": "classes/spells" },
    "ts": 1509244539547758,
    "data": {
      "name": "Water Dragon's Claw",
      "element": [ "water", "fire" ],
      "spellbook": { "@ref": "classes/spellbooks/181388642139243008" }
    }
  },
  {
    "ref": { "@ref": "classes/spells/181388642088911360" },
    "class": { "@ref": "classes/spells" },
    "ts": 1509244539235128,
    "data": {
      "name": "Hippo's Wallow",
      "element": [ "water", "earth" ]
    }
  }
]

=> [
  {
    "ref": { "@ref": "classes/spells/181388642046968320" },
    "class": { "@ref": "classes/spells" },
    "ts": 1509244539547758,
    "data": {
      "name": "Fire Beak",
      "element": [ "air", "fire" ],
      "spellbook": { "@ref": "classes/spellbooks/181388642139243008" }
    }
  },
  {
    "ref": { "@ref": "classes/spells/181388642071085568" },
    "class": { "@ref": "classes/spells" },
    "ts": 1509244539547758,
    "data": {
      "name": "Water Dragon's Claw",
      "element": [ "water", "fire" ],
      "spellbook": { "@ref": "classes/spellbooks/181388642139243008" }
    }
  },
  {
    "ref": { "@ref": "classes/spells/181388642088911360" },
    "class": { "@ref": "classes/spells" },
    "ts": 1509244539235128,
    "data": {
      "name": "Hippo's Wallow",
      "element": [ "water", "earth" ]
    }
  }
]

=> [
  {
    "ref": { "@ref": "classes/spells/181388642046968320" },
    "class": { "@ref": "classes/spells" },
    "ts": 1509244539547758,
    "data": {
      "name": "Fire Beak",
      "element": [ "air", "fire" ],
      "spellbook": { "@ref": "classes/spellbooks/181388642139243008" }
    }
  },
  {
    "ref": { "@ref": "classes/spells/181388642071085568" },
    "class": { "@ref": "classes/spells" },
    "ts": 1509244539547758,
    "data": {
      "name": "Water Dragon's Claw",
      "element": [ "water", "fire" ],
      "spellbook": { "@ref": "classes/spellbooks/181388642139243008" }
    }
  },
  {
    "ref": { "@ref": "classes/spells/181388642088911360" },
    "class": { "@ref": "classes/spells" },
    "ts": 1509244539235128,
    "data": {
      "name": "Hippo's Wallow",
      "element": [ "water", "earth" ]
    }
  }
]

=> [
  {
    "ref": { "@ref": "classes/spells/181388642046968320" },
    "class": { "@ref": "classes/spells" },
    "ts": 1509244539547758,
    "data": {
      "name": "Fire Beak",
      "element": [ "air", "fire" ],
      "spellbook": { "@ref": "classes/spellbooks/181388642139243008" }
    }
  },
  {
    "ref": { "@ref": "classes/spells/181388642071085568" },
    "class": { "@ref": "classes/spells" },
    "ts": 1509244539547758,
    "data": {
      "name": "Water Dragon's Claw",
      "element": [ "water", "fire" ],
      "spellbook": { "@ref": "classes/spellbooks/181388642139243008" }
    }
  },
  {
    "ref": { "@ref": "classes/spells/181388642088911360" },
    "class": { "@ref": "classes/spells" },
    "ts": 1509244539235128,
    "data": {
      "name": "Hippo's Wallow",
      "element": [ "water", "earth" ]
    }
  }
]

=> [ { ref: Ref(id=181388642046968320, class=Ref(id=spells, class=Ref(id=classes))),
    ts: 1509244539547758,
    data:
     { name: "Fire Beak",
       element: [ "air", "fire" ],
       spellbook: Ref(id=181388642139243008, class=Ref(id=spellbooks, class=Ref(id=classes))) } },
  { ref: Ref(id=181388642071085568, class=Ref(id=spells, class=Ref(id=classes))),
    ts: 1509244539547758,
    data:
     { name: "Water Dragon's Claw",
       element: [ "water", "fire" ],
       spellbook: Ref(id=181388642139243008, class=Ref(id=spellbooks, class=Ref(id=classes))) } },
  { ref: Ref(id=181388642088911360, class=Ref(id=spells, class=Ref(id=classes))),
    ts: 1509244539235128,
    data:
     { name: "Hippo's Wallow",
       element: [ "water", "earth" ] } } ]

Related References

KeyFromSecret


KeyFromSecret( secert )

KeyFromSecret( secert )

f.KeyFromSecret( secert )

KeyFromSecret( secert )

key_from_secret( secert )

key_from_secret  secert

KeyFromSecret secert )

KeyFromSecret( secert )

Description

The KeyFromSecret function retrieves a key instance given a key’s secret string.

Parameter

Argument Type Definition and Requirements
secret String The secret (i.e password) associated with a given key object

Returns

An object containing data returned by KeyFromSecret operations.

Field Name Field Type Definition and Requirements
ref Reference The reference identifies the key instance that was retrieved.
ts Long The timestamp associated with the creation of the key instance.
database Reference A refence to the database the key is protecting.
role String The security role for this key.
hashed_secret String The hash of the secret.

Examples

The query below retrieves a key instance by providing a given secret.


curl https://db.fauna.com/ \
    -u fnAChGwBacACAEZtRZFDXpyjIvq-sln34m-va4Km: \
    -d '{ "key_from_secret": "fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL" }'

client.Query(
  KeyFromSecret("fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL"));

System.out.println(
    client.query(
      KeyFromSecret(
        Value("fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL")
      )
    ).get());

result, _ := client.Query(
    f.KeyFromSecret("fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL"),
)

fmt.Println(result)

client.query(
  KeyFromSecret("fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL"))

client.query(
  q.key_from_secret("fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL"))

$client.query do
  key_from_secret 'fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL'
end

client.query(
    KeyFromSecret(
        "fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL"
    )
)

client.query(q.KeyFromSecret("fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL"))
  .then((ret) => console.log(ret));

=> HTTP/1.1 200 OK
{
  "resource": {
    "ref": { "@ref": "keys/181388638431478272" },
    "class": { "@ref": "keys" },
    "ts": 1509244535744675,
    "database": { "@ref": "databases/prydain" },
    "role": "server",
    "hashed_secret": "$2a$05$4kVnCWuJuaJYXz4ISHk1ge32/Otwya6QUVu.SSO7SbOn.fzbXLKFu"
  }
}

=> {
  "ref": { "@ref": "keys/181388638431478272" },
  "class": { "@ref": "keys" },
  "ts": 1509244535744675,
  "database": { "@ref": "databases/prydain" },
  "role": "server",
  "hashed_secret": "$2a$05$4kVnCWuJuaJYXz4ISHk1ge32/Otwya6QUVu.SSO7SbOn.fzbXLKFu"
}

=> {
  ref: ref(id = "200886770939724288", class = ref(id = "keys")),
  ts: 1527839403941254,
  database: ref(id = "prydain", class = ref(id = "databases")),
  role: "server",
  hashed_secret: "$2a$05$Gi4GT2NU2LGjb7LuoNAvue/eScTIkaEk1xeBLDOZSCiX2seM/zgDS"
}

=> map[ref:{181388638431478272 0xc42023fc00 <nil>} ts:1509244535744675 database:{prydain 0xc42023fda0 <nil>} role:server hashed_secret:$2a$05$4kVnCWuJuaJYXz4ISHk1ge32/Otwya6QUVu.SSO7SbOn.fzbXLKFu]

=> {
  "ref": { "@ref": "keys/181388638431478272" },
  "class": { "@ref": "keys" },
  "ts": 1509244535744675,
  "database": { "@ref": "databases/prydain" },
  "role": "server",
  "hashed_secret": "$2a$05$4kVnCWuJuaJYXz4ISHk1ge32/Otwya6QUVu.SSO7SbOn.fzbXLKFu"
}

=> {
  "ref": { "@ref": "keys/181388638431478272" },
  "class": { "@ref": "keys" },
  "ts": 1509244535744675,
  "database": { "@ref": "databases/prydain" },
  "role": "server",
  "hashed_secret": "$2a$05$4kVnCWuJuaJYXz4ISHk1ge32/Otwya6QUVu.SSO7SbOn.fzbXLKFu"
}

=> {
  "ref": { "@ref": "keys/181388638431478272" },
  "class": { "@ref": "keys" },
  "ts": 1509244535744675,
  "database": { "@ref": "databases/prydain" },
  "role": "server",
  "hashed_secret": "$2a$05$4kVnCWuJuaJYXz4ISHk1ge32/Otwya6QUVu.SSO7SbOn.fzbXLKFu"
}

=> {
  "ref": { "@ref": "keys/181388638431478272" },
  "class": { "@ref": "keys" },
  "ts": 1509244535744675,
  "database": { "@ref": "databases/prydain" },
  "role": "server",
  "hashed_secret": "$2a$05$4kVnCWuJuaJYXz4ISHk1ge32/Otwya6QUVu.SSO7SbOn.fzbXLKFu"
}

=> { ref: Ref(id=181388638431478272, class=Ref(id=keys)),
  ts: 1509244535744675,
  database: Ref(id=prydain, class=Ref(id=databases)),
  role: "server",
  hashed_secret: "$2a$05$4kVnCWuJuaJYXz4ISHk1ge32/Otwya6QUVu.SSO7SbOn.fzbXLKFu" }

Related References

Select


Select( path, from, param_object )

Select( path, from, param_object )

Select( path, from, param_object )

Select( path, from, param_object )

select( path, from, param_object )

select  path, from, param_object

Select( path, from, param_object )

Select( path, from, param_object )

Description

The select function extracts a single value from a document. It extracts the value specified by the “path” argument out of the “from” argument and returns the value. If the “path” does not exist, the optional “default” object is return. If the default object is not provided then an error is returned.

Parameter

Argument Type Definition and Requirements
path Long | String The path to a field in the document to extract
from Object The object containing the data to be extracted.
default Object Optional - The value to be returned if the path does not exist.

Returns

The value at the path.

Examples

The query below extracts from the top level object named “favorites” and second level array called “foods” the value in position 1 of the array. This value is “munchings”.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{
          "select": [ "favorites", "foods", 1 ],
          "from": {
            "object": {
              "favorites": {
                "object": { "foods": [ "crunchings", "munchings", "lunchings" ] }
              }
            }
          }
        }'

client.Query(
  Select(
    Arr("favorites", "foods", 1),
    Obj(
      "favorites", Obj("foods", Arr("crunchings", "munchings", "lunchings"))
    )));

System.out.println(
    client.query(
      Select(
        Arr(Value("favorites"), Value("foods"), Value(1)),
        Obj(
           "favorites", Obj(
             "foods", Arr(
              Value("crunchings"),
              Value("munchings"),
              Value("lunchings")
            )
          )
        )
      )
    )
.get());

result, _ := client.Query(
    f.Select(
        f.Arr{"favorites", "foods", 1},
        f.Obj{
            "favorites": f.Obj{
                "foods": f.Arr{"crunchings", "munchings", "lunchings"},
            },
        },
    ),
)

fmt.Println(result)

client.query(
  Select(
    Arr("favorites", "foods", 1),
    Obj(
      "favorites" -> Obj("foods" -> Arr("crunchings", "munchings", "lunchings"))
    )))

client.query(
  q.select(
    ["favorites", "foods", 1],
    {
      "favorites": {"foods": ["crunchings", "munchings", "lunchings"]}
    }
  ))

$client.query do
  select ['favorites', 'foods', 1],
         favorites: { foods: ['crunchings', 'munchings', 'lunchings'] }
end

client.query(
    Select(
        path: "favorites", "foods", 1,
        from: Obj(
            "favorites" => Obj(
                "foods" => Arr("crunchings", "munchings", "lunchings")
            )
        )
    )
)

client.query(
  q.Select(
    ["favorites", "foods", 1],
    { favorites: { foods: ["crunchings", "munchings", "lunchings"] } }))
.then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{ "resource": "munchings" }

=> "munchings"

=> "munchings"

=> munchings

=> "munchings"

=> "munchings"

=> "munchings"

=> "munchings"

=> munchings

In the example below select extracts the “id” attributes from ref object.


curl https://db.fauna.com/ \
    -u fnAChGwBacACAEZtRZFDXpyjIvq-sln34m-va4Km: \
    -d '{ "select": [ "id" ], "from": { "database": "prydain" } }'

client.Query(Select(Arr("id"), Database("prydain")));

System.out.println(
      client.query(
         Select(Arr(Value("id")), Database(Value("prydain"))))
      .get());

result, _ := client.Query(f.Select(f.Arr{"id"}, f.Database("prydain")))

fmt.Println(result)

client.query(Select(Arr("id"), Database("prydain")))

client.query(q.select(["id"], q.database("prydain")))

$client.query do
  select ['id'], database('prydain')
end

client.query(Select(path: "id", from: Database("prydain")))

client.query(q.Select(["id"], q.Database("prydain")))
  .then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{ "resource": "prydain" }

=> "prydain"

=> "prydain"

=> prydain

=> "prydain"

=> "prydain"

=> "prydain"

=> "prydain"

=> prydain

Related References

SelectAll


SelectAll( path, from )

SelectAll( path, from )

SelectAll( path, from )

SelectAll( path, from )

selectAll( path, from )

SelectAll( path, from )

SelectAll( path, from )

Description

The SelectAll function extracts one or more values from a document. It is very usefull when extracting multiple values in an array. It extracts all the values specified by the “path” argument out of the “from” argument and returns the values as an Array. If the path does not exist an empty array is retruned.

Parameter

Argument Type Definition and Requirements
path String The path to the filed in the document to extract
from Object The object containing the data to be extracted.

Returns

The value(s) specified by the path.

Examples


System.out.println(
  client.query(
    SelectAll(
      Arr(Value("favorites"), Value("name")),
        Obj(
          "favorites",  Arr(
                        Obj("name", Value("Jane")),
                        Obj("name", Value("John")),
                        Obj("name", Value("Thomas"))
                        )
        )
    )
  )
.get());

=> ["Jane", "John", "Thomas"]

Related References

Paginate


Paginate( input, [ts], [after], [before], [size], [events], [sources] )

Paginate( input, [ts], [after], [before], [size], [events], [sources] )

Paginate( input, [ts], [after], [before], [size], [events], [sources] )

Paginate( input, [ts], [after], [before], [size], [events], [sources] )

paginate( input, [ts], [after], [before], [size], [events], [sources] )

paginate  input, [ts], [after], [before], [size], [events], [sources]

Paginate( input, [ts], [after], [before], [size], [events], [sources] )

Paginate( input, [ts], [after], [before], [size], [events], [sources] )

Description

The Paginate function simplifies the traversal of a query’s results. It is best utilized when the result of a query returns more than one object or an unknown number of objects. It provides cursor like semantics allowing the caller to walk both forward and backward in configurable sized pages through the results.

Parameter

Field Name Field Type Definition and Requirements
input Set | Ref  
ts Integer or time value Optional, default current, Return the result set at the specified point in time (number of UNIX microseconds or time value).
after Cursor Optional, Return the next page of results after this cursor (inclusive).
before Cursor Optional, Return the previous page of results before this cursor (exclusive).
size Integer Optional, default 16 Maximum number of results to return in a single page. The maximum page size is 1024.
events Boolean Optional, default false If true, return a page from the event history of the set.
sources Boolean Optional, default false If true, includes the source of thruth providing why this object was included in the result set.

The type of pagination cursor depends on whether the page is from a set or events timeline. Set cursors may be a single scalar value, or an array of values.

Events timeline cursors may be one of:

  • An Integer representing a timestamp.
  • A @ts value.
  • A @date value. Dates will be interpreted as midnight on that date, in UTC.
  • An partial Event object: ts, ts and action, or all of ts, action, and resource must be specified.

Note: It’s possible to dead-reckon through a set by specifying a synthetic cursor. For a set in descending order, { "before": null } or { "after": 0 } will yield the first and last pages of the set, respectively.

Returns

An object containing both the data and metadata about the results of create operations.

Field Name Field Type Definition and Requirements
page Page The page contains data array along with before and after cursors.

Examples

Simple page get:


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{
          "paginate": {
            "union": [
              {
                "match": { "index": "spells_by_element" },
                "terms": "fire"
              },
              {
                "match": { "index": "spells_by_element" },
                "terms": "water"
              }
            ]
          }
        }'

client.Query(
  Paginate(
    Union(
      Match(Index("spells_by_element"), "fire"),
      Match(Index("spells_by_element"), "water"))));

System.out.println(
      client.query(
          Paginate(
              Union(
                   Match(Index(Value("spells_by_element")), Value("fire")),
                   Match(Index(Value("spells_by_element")), Value("water"))
              )
          )
      ).get());

result, _ := client.Query(
    f.Paginate(
        f.Union(
            f.MatchTerm(f.Index("spells_by_element"), "fire"),
            f.MatchTerm(f.Index("spells_by_element"), "water"),
        ),
    ),
)

fmt.Println(result)

client.query(
  Paginate(
    Union(
      Match(Index("spells_by_element"), "fire"),
      Match(Index("spells_by_element"), "water"))))

client.query(
  q.paginate(
    q.union(
      q.match(q.index("spells_by_element"), "fire"),
      q.match(q.index("spells_by_element"), "water")
    )
  ))

$client.query do
  paginate union(match(index('spells_by_element'), 'fire'),
                 match(index('spells_by_element'), 'water'))
end

client.query(
    Paginate(
        Union(
            Match(
                index: Index("spells_by_element"),
                terms: "fire"
            ),
            Match(
                index: Index("spells_by_element"),
                terms: "water"
            )
        )
    )
)

client.query(
  q.Paginate(
    q.Union(
      q.Match(q.Index("spells_by_element"), "fire"),
      q.Match(q.Index("spells_by_element"), "water"))))
.then((ret) => console.log(ret));

=> HTTP/1.1 200 OK
{
  "resource": {
    "data": [
      { "@ref": "classes/spells/181388642046968320" },
      { "@ref": "classes/spells/181388642071085568" },
      { "@ref": "classes/spells/181388642088911360" }
    ]
  }
}

=> {
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/spells/181388642071085568" },
    { "@ref": "classes/spells/181388642088911360" }
  ]
}

=> {
  data: [
    ref(id = "181388642046968320", class = ref(id = "spells", class = ref(id = "classes"))),
    ref(id = "181388642071085568", class = ref(id = "spells", class = ref(id = "classes"))),
    ref(id = "181388642088911360", class = ref(id = "spells", class = ref(id = "classes")))
  ]
}

=> map[data:[{181388642046968320 0xc4201c7dc0 <nil>} {181388642071085568 0xc4201c7fe0 <nil>} {181388642088911360 0xc42021c220 <nil>}]]

=> {
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/spells/181388642071085568" },
    { "@ref": "classes/spells/181388642088911360" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/spells/181388642071085568" },
    { "@ref": "classes/spells/181388642088911360" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/spells/181388642071085568" },
    { "@ref": "classes/spells/181388642088911360" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/spells/181388642071085568" },
    { "@ref": "classes/spells/181388642088911360" }
  ]
}

=> { data:
  [ Ref(id=181388642046968320, class=Ref(id=spells, class=Ref(id=classes))),
    Ref(id=181388642071085568, class=Ref(id=spells, class=Ref(id=classes))),
    Ref(id=181388642088911360, class=Ref(id=spells, class=Ref(id=classes))) ] }

With sources:


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{
          "paginate": {
            "union": [
              {
                "match": { "index": "spells_by_element" },
                "terms": "fire"
              },
              {
                "match": { "index": "spells_by_element" },
                "terms": "water"
              }
            ]
          },
          "sources": true
        }'

client.Query(
  Paginate(
    Union(
      Match(Index("spells_by_element"), "fire"),
      Match(Index("spells_by_element"), "water")),
    sources: true));

System.out.println(
    client.query(
        Paginate(
            Union(
                Match(Index(Value("spells_by_element")), Value("fire")),
                Match(Index(Value("spells_by_element")), Value("water"))
            )
        ).sources(Value(true))
    ).get());

result, _ := client.Query(
    f.Paginate(
        f.Union(
            f.MatchTerm(f.Index("spells_by_element"), "fire"),
            f.MatchTerm(f.Index("spells_by_element"), "water"),
        ),
        f.Sources(true),
    ),
)

fmt.Println(result)

client.query(
  Paginate(
    Union(
      Match(Index("spells_by_element"), "fire"),
      Match(Index("spells_by_element"), "water")),
    sources = true))

client.query(
  q.paginate(
    q.union(
      q.match(q.index("spells_by_element"), "fire"),
      q.match(q.index("spells_by_element"), "water")
    ),
    sources=True
  ))

$client.query do
  paginate union(match(index('spells_by_element'), 'fire'),
                 match(index('spells_by_element'), 'water')),
           sources: true
end

client.query(
    Paginate(
        Union(
            Match(
                index: Index("spells_by_element"),
                terms: "fire"
            ),
            Match(
                index: Index("spells_by_element"),
                terms: "water"
            )
        ),
        sources: true
    )
)

client.query(
  q.Paginate(
    q.Union(
      q.Match(q.Index("spells_by_element"), "fire"),
      q.Match(q.Index("spells_by_element"), "water")),
    { sources: true }))
.then((ret) => console.log(ret));

=> HTTP/1.1 200 OK
{
  "resource": {
    "data": [
      {
        "value": { "@ref": "classes/spells/181388642046968320" },
        "sources": [
          {
            "@set": {
              "match": { "@ref": "indexes/spells_by_element" },
              "terms": "fire"
            }
          }
        ]
      },
      {
        "value": { "@ref": "classes/spells/181388642071085568" },
        "sources": [
          {
            "@set": {
              "match": { "@ref": "indexes/spells_by_element" },
              "terms": "fire"
            }
          },
          {
            "@set": {
              "match": { "@ref": "indexes/spells_by_element" },
              "terms": "water"
            }
          }
        ]
      },
      {
        "value": { "@ref": "classes/spells/181388642088911360" },
        "sources": [
          {
            "@set": {
              "match": { "@ref": "indexes/spells_by_element" },
              "terms": "water"
            }
          }
        ]
      }
    ]
  }
}

=> {
  "data": [
    {
      "value": { "@ref": "classes/spells/181388642046968320" },
      "sources": [
        {
          "@set": {
            "match": { "@ref": "indexes/spells_by_element" },
            "terms": "fire"
          }
        }
      ]
    },
    {
      "value": { "@ref": "classes/spells/181388642071085568" },
      "sources": [
        {
          "@set": {
            "match": { "@ref": "indexes/spells_by_element" },
            "terms": "fire"
          }
        },
        {
          "@set": {
            "match": { "@ref": "indexes/spells_by_element" },
            "terms": "water"
          }
        }
      ]
    },
    {
      "value": { "@ref": "classes/spells/181388642088911360" },
      "sources": [
        {
          "@set": {
            "match": { "@ref": "indexes/spells_by_element" },
            "terms": "water"
          }
        }
      ]
    }
  ]
}

=> {
  data: [  
    {
      value: ref(id = "181388642046968320", class = ref(id = "spells", class = ref(id = "classes"))), 
      sources: [
        { 
          @set = {
            match: ref(id = "spells_by_element", class = ref(id = "indexes")), 
            terms: "fire"
          } 
        }
      ]
    },      
    {
      value: ref(id = "181388642071085568", class = ref(id = "spells", class = ref(id = "classes"))), 
      sources: [
        { 
          @set = {
            match: ref(id = "spells_by_element", class = ref(id = "indexes")), 
            terms: "fire"
          } 
        }, 
        { 
          @set = {
            match: ref(id = "spells_by_element", class = ref(id = "indexes")), 
            terms: "water"
          } 
        }
      ]
    },    
    {
      value: ref(id = "181388642088911360", class = ref(id = "spells", class = ref(id = "classes"))), 
      sources: [
        { 
          @set = {
            match: ref(id = "spells_by_element", class = ref(id = "indexes")), 
            terms: "water"
          } 
        }
      ]
    }
  ]
}

=> map[data:[
  map[value:{181388642046968320 0xc42024a960 <nil>} sources:[{map[match:{spells_by_element 0xc42024ab00 <nil>} terms:fire]}]]
  map[value:{181388642071085568 0xc42024ada0 <nil>} sources:[{map[terms:fire match:{spells_by_element 0xc42024af40 <nil>}]} {map[match:{spells_by_element 0xc42024b100 <nil>} terms:water]}]]
  map[value:{181388642088911360 0xc42024b3e0 <nil>} sources:[{map[match:{spells_by_element 0xc42024b580 <nil>} terms:water]}]]
]]

=> {
  "data": [
    {
      "value": { "@ref": "classes/spells/181388642046968320" },
      "sources": [
        {
          "@set": {
            "match": { "@ref": "indexes/spells_by_element" },
            "terms": "fire"
          }
        }
      ]
    },
    {
      "value": { "@ref": "classes/spells/181388642071085568" },
      "sources": [
        {
          "@set": {
            "match": { "@ref": "indexes/spells_by_element" },
            "terms": "fire"
          }
        },
        {
          "@set": {
            "match": { "@ref": "indexes/spells_by_element" },
            "terms": "water"
          }
        }
      ]
    },
    {
      "value": { "@ref": "classes/spells/181388642088911360" },
      "sources": [
        {
          "@set": {
            "match": { "@ref": "indexes/spells_by_element" },
            "terms": "water"
          }
        }
      ]
    }
  ]
}

=> {
  "data": [
    {
      "value": { "@ref": "classes/spells/181388642046968320" },
      "sources": [
        {
          "@set": {
            "match": { "@ref": "indexes/spells_by_element" },
            "terms": "fire"
          }
        }
      ]
    },
    {
      "value": { "@ref": "classes/spells/181388642071085568" },
      "sources": [
        {
          "@set": {
            "match": { "@ref": "indexes/spells_by_element" },
            "terms": "fire"
          }
        },
        {
          "@set": {
            "match": { "@ref": "indexes/spells_by_element" },
            "terms": "water"
          }
        }
      ]
    },
    {
      "value": { "@ref": "classes/spells/181388642088911360" },
      "sources": [
        {
          "@set": {
            "match": { "@ref": "indexes/spells_by_element" },
            "terms": "water"
          }
        }
      ]
    }
  ]
}

=> {
  "data": [
    {
      "value": { "@ref": "classes/spells/181388642046968320" },
      "sources": [
        {
          "@set": {
            "match": { "@ref": "indexes/spells_by_element" },
            "terms": "fire"
          }
        }
      ]
    },
    {
      "value": { "@ref": "classes/spells/181388642071085568" },
      "sources": [
        {
          "@set": {
            "match": { "@ref": "indexes/spells_by_element" },
            "terms": "fire"
          }
        },
        {
          "@set": {
            "match": { "@ref": "indexes/spells_by_element" },
            "terms": "water"
          }
        }
      ]
    },
    {
      "value": { "@ref": "classes/spells/181388642088911360" },
      "sources": [
        {
          "@set": {
            "match": { "@ref": "indexes/spells_by_element" },
            "terms": "water"
          }
        }
      ]
    }
  ]
}

=> {
  "data": [
    {
      "value": { "@ref": "classes/spells/181388642046968320" },
      "sources": [
        {
          "@set": {
            "match": { "@ref": "indexes/spells_by_element" },
            "terms": "fire"
          }
        }
      ]
    },
    {
      "value": { "@ref": "classes/spells/181388642071085568" },
      "sources": [
        {
          "@set": {
            "match": { "@ref": "indexes/spells_by_element" },
            "terms": "fire"
          }
        },
        {
          "@set": {
            "match": { "@ref": "indexes/spells_by_element" },
            "terms": "water"
          }
        }
      ]
    },
    {
      "value": { "@ref": "classes/spells/181388642088911360" },
      "sources": [
        {
          "@set": {
            "match": { "@ref": "indexes/spells_by_element" },
            "terms": "water"
          }
        }
      ]
    }
  ]
}

=> { data:
   [ { value: Ref(id=181388642046968320, class=Ref(id=spells, class=Ref(id=classes))),
       sources: [Object] },
     { value: Ref(id=181388642071085568, class=Ref(id=spells, class=Ref(id=classes))),
       sources: [Object] },
     { value: Ref(id=181388642088911360, class=Ref(id=spells, class=Ref(id=classes))),
       sources: [Object] } ] }

With events:


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{
          "paginate": {
            "union": [
              {
                "match": { "index": "spells_by_element" },
                "terms": "fire"
              },
              {
                "match": { "index": "spells_by_element" },
                "terms": "water"
              }
            ]
          },
          "events": true
        }'

client.Query(
  Paginate(
    Union(
      Match(Index("spells_by_element"), "fire"),
      Match(Index("spells_by_element"), "water")),
    events: true));

System.out.println(
      client.query(
         Paginate(
             Union(
               Match(Index(Value("spells_by_element")), Value("fire")),
               Match(Index(Value("spells_by_element")), Value("water"))
             )
         ).events(Value(true))
      ).get());

result, _ := client.Query(
    f.Paginate(
        f.Events(
            f.Union(
                f.MatchTerm(f.Index("spells_by_element"), "fire"),
                f.MatchTerm(f.Index("spells_by_element"), "water"),
            ),
        ),
    ),
)

fmt.Println(result)

client.query(
  Paginate(
    Union(
      Match(Index("spells_by_element"), "fire"),
      Match(Index("spells_by_element"), "water")),
    events = true))

client.query(
  q.paginate(
    q.union(
      q.match(q.index("spells_by_element"), "fire"),
      q.match(q.index("spells_by_element"), "water")
    ),
    events=True
  ))

$client.query do
  paginate union(match(index('spells_by_element'), 'fire'),
                 match(index('spells_by_element'), 'water')),
           events: true
end

client.query(
    Paginate(
        Union(
            Match(
                index: Index("spells_by_element"),
                terms: "fire"
            ),
            Match(
                index: Index("spells_by_element"),
                terms: "water"
            )
        ),
        events: true
    )
)

client.query(
  q.Paginate(
    q.Union(
      q.Match(q.Index("spells_by_element"), "fire"),
      q.Match(q.Index("spells_by_element"), "water")),
    { events: true }))
.then((ret) => console.log(ret));

=> HTTP/1.1 200 OK
{
  "resource": {
    "data": [
      {
        "ts": 1509244539203043,
        "action": "create",
        "resource": { "@ref": "classes/spells/181388642046968320" }
      },
      {
        "ts": 1509244539223511,
        "action": "create",
        "resource": { "@ref": "classes/spells/181388642071085568" }
      },
      {
        "ts": 1509244539235128,
        "action": "create",
        "resource": { "@ref": "classes/spells/181388642088911360" }
      }
    ]
  }
}

=> {
  "data": [
    {
      "ts": 1509244539203043,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" }
    },
    {
      "ts": 1509244539223511,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" }
    },
    {
      "ts": 1509244539235128,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642088911360" }
    }
  ]
}

=> {
  data: [
    {
      ts: 1526663274438247, 
      action: "add", 
      instance: ref(id = "181388642071085568", class = ref(id = "spells", class = ref(id = "classes")))
    },
    {
      ts: 1526663274504812, 
      action: "add", 
      instance: ref(id = "181388642046968320", class = ref(id = "spells", class = ref(id = "classes")))
    },
    {
      ts: 1526663274516453, 
      action: "add", 
      instance: ref(id = "181388642088911360", class = ref(id = "spells", class = ref(id = "classes")))
    }
  ]
}

=> map[data:[
  map[instance:{181388642046968320 0xc420205300 <nil>} action:add ts:1509244539203043]
  map[instance:{181388642071085568 0xc4202055c0 <nil>} action:add ts:1509244539223511]
  map[instance:{181388642088911360 0xc4202058a0 <nil>} action:add ts:1509244539235128]
]]

=> {
  "data": [
    {
      "ts": 1509244539203043,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" }
    },
    {
      "ts": 1509244539223511,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" }
    },
    {
      "ts": 1509244539235128,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642088911360" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1509244539203043,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" }
    },
    {
      "ts": 1509244539223511,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" }
    },
    {
      "ts": 1509244539235128,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642088911360" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1509244539203043,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" }
    },
    {
      "ts": 1509244539223511,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" }
    },
    {
      "ts": 1509244539235128,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642088911360" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1509244539203043,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" }
    },
    {
      "ts": 1509244539223511,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" }
    },
    {
      "ts": 1509244539235128,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642088911360" }
    }
  ]
}

=> { data:
   [ { ts: 1509244539203043,
       create: 'add',
       instance: Ref(id=181388642046968320, class=Ref(id=spells, class=Ref(id=classes))) },
     { ts: 1509244539203043,
       create: 'add',
       instance: Ref(id=181388642071085568, class=Ref(id=spells, class=Ref(id=classes))) },
     { ts: 1509244539203043,
       create: 'add',
       instance: Ref(id=181388642088911360, class=Ref(id=spells, class=Ref(id=classes))) } ] }

Related References

Write Functions

Functions which create, modify, and delete schema, instance, and instance history.

Schema Instance Instance History
  • CreateClass
  • CreateDatabase
  • CreateFunction
  • CreateIndex
  • CreateKey
  • Create
  • Delete
  • Replace
  • Update
  • Insert
  • Remove

Create


Create( class_ref, parm_object )

Create( class_ref, param_object )

Create( class_ref, param_object )

Create( class_ref, param_object )

create( class_ref, param_object )

create class_ref, param_object

Create( class_ref, param_object )

Create( class_ref, param_object )

Description

The create function adds a new instance to a class. The class_ref indicates what class of instance is created, while the param_object contains the instance data and optional metadata.

Parameters

Argument Type Definition and Requirements
class_ref Reference A reference type containing the class the instance will be added into.
param_object Object The param_object fields are described below.
param_object
Field Name Field Type Definition and Requirements
data Object The user’s single, changeable document.
credentials Object The permissions for this instance.
delegates Object A group or delegates to check security. See delegates in the Security Reference.

Returns

An instance object containing both the data and metadata about the results of the operations.

Field Name Field Type Definition and Requirements
ref Reference The reference is an automatically generated identifier within the database uniquely identifying the instance created.
data Object The data that was inserted with the instance.
ts Long The timestamp associated with the creation of the instance.

Examples

The query below executes a create instance by providing a reference to the class “spells” and parameters object with a data field. The data field contains the user data to be inserted for this instance.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{
          "create": { "class": "spells" },
          "params": {
            "object": {
              "data": {
                "object": {
                  "name": "Mountainous Thunder",
                  "element": "air",
                  "cost": 15
                }
              }
            }
          }
        }'

client.Query(
  Create(
    Class("spells"),
    Obj(
      "data", Obj(
        "name", "Mountainous Thunder",
        "element", "air",
        "cost", 15
      )
    )));

System.out.println(
   client.query(
      Create(
            Class(Value("spells")),
            Obj(
               "data", Obj(
                          "name", Value("Mountainous Thunder"),
                          "element", Value("air"),
                          "cost", Value(15)
                       )
            ))
   ).get());

result, _ := client.Query(
    f.Create(
        f.Class("spells"),
        f.Obj{
            "data": f.Obj{
                "name": "Mountainous Thunder",
                "element": "air",
                "cost": 15,
            },
        },
    ),
)

fmt.Println(result)

client.query(
  Create(
    Class("spells"),
    Obj(
      "data" -> Obj(
        "name" -> "Mountainous Thunder",
        "element" -> "air",
        "cost" -> 15
      )
    )))

client.query(
  q.create(
    q.class_expr("spells"),
    {
      "data": {"name": "Mountainous Thunder", "element": "air", "cost": 15}
    }
  ))

$client.query do
  create class_('spells'),
         data: { name: 'Mountainous Thunder', element: 'air', cost: 15 }
end

client.query(
    Create(
        at: Class("spells"),
        Obj(
            "data" => Obj(
                "name" => "Mountainous Thunder",
                "element" => "air",
                "cost" => 15
            )
        )
    )
)

client.query(
  q.Create(q.Class("spells"),
    { data: { name: "Mountainous Thunder", element: "air", cost: 15 } }))
.then((ret) => console.log(ret))

=> HTTP/1.1 201 Created
{
  "resource": {
    "ref": { "@ref": "classes/spells/181388642581742080" },
    "class": { "@ref": "classes/spells" },
    "ts": 1509244539709690,
    "data": {
      "name": "Mountainous Thunder",
      "element": "air",
      "cost": 15
    }
  }
}

=> {
  "ref": { "@ref": "classes/spells/181388642581742080" },
  "class": { "@ref": "classes/spells" },
  "ts": 1509244539709690,
  "data": {
    "name": "Mountainous Thunder",
    "element": "air",
    "cost": 15
  }
}

=> {
  ref: ref(id = "181388642581742080", class = ref(id = "spells", class = ref(id = "classes"))),
  ts: 1526674566636715,
  data: {
    name: "Mountainous Thunder",
    element: "air",
    cost: 15
  }
}

=> map[ref:{181388642581742080 0xc420215ee0 <nil>} ts:1509244539709690 data:map[cost:15 element:air name:Mountainous Thunder]]

=> {
  "ref": { "@ref": "classes/spells/181388642581742080" },
  "class": { "@ref": "classes/spells" },
  "ts": 1509244539709690,
  "data": {
    "name": "Mountainous Thunder",
    "element": "air",
    "cost": 15
  }
}

=> {
  "ref": { "@ref": "classes/spells/181388642581742080" },
  "class": { "@ref": "classes/spells" },
  "ts": 1509244539709690,
  "data": {
    "name": "Mountainous Thunder",
    "element": "air",
    "cost": 15
  }
}

=> {
  "ref": { "@ref": "classes/spells/181388642581742080" },
  "class": { "@ref": "classes/spells" },
  "ts": 1509244539709690,
  "data": {
    "name": "Mountainous Thunder",
    "element": "air",
    "cost": 15
  }
}

=> {
  "ref": { "@ref": "classes/spells/181388642581742080" },
  "class": { "@ref": "classes/spells" },
  "ts": 1509244539709690,
  "data": {
    "name": "Mountainous Thunder",
    "element": "air",
    "cost": 15
  }
}

=> { ref:
  Ref(id=181388642581742080, class=Ref(id=spells, class=Ref(id=classes))),
  ts: 1527274715273882,
  data: { name: 'Mountainous Thunder', element: 'air', cost: 15 } }

Related References

CreateClass


CreateClass( param_object )

CreateClass( param_object )

CreateClass( param_object )

CreateClass( param_object )

create_class( param_object )

create_class name

CreateClass( param_object )

CreateClass( param_object )

Description

The CreateClass function is used to create a class which groups instance objects. Once the class has been created, it is possible to create instances in the class. You cannot create a class and insert records into that class in the same transaction.

Parameters

Argument Type Definition and Requirements
param_object Object The param_object fields are described below.

param_object

Field Name Field Type Definition and Requirements
name String The name of a class. Classes cannot be named any of the following reserved words: events, set, self, instances, or “_”.
data Object Optional - This is user-defined metadata for the class. It is provided for the developer to store information at the class level.
history_days Long Optional - The number of days instance history is retained for this class. Setting the history_days to null will retain this class’s history forever. It defaults to 30 days.
ttl_days Long Optional - The number of days instances are retained for this class. Instances which have not been updated within the configured TTL duration will be removed. Setting the ttl_days to null will retain instances forever. It defaults to forever.
permissions Object Optional - Provides the ability to enable permissions at the class level. See class permissions for additional details.

Returns

An object containing the fields returned by the CreateClass operation is described below.

Field Name Field Type Definition and Requirements
ref Reference The reference is an automatically generated identifier within the database to uniquely identify the class that was created.
name String The name of the class that was created.
ts Long The timestamp associated with the creation of the instance.
history_days Long The number of days to retain history.

Examples

The query below creates a class called “boons” with defaults.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "create_class": { "object": { "name": "boons" } } }'

client.Query(CreateClass(Obj("name", "boons")));

System.out.println(
      client.query(
            CreateClass(Obj("name", Value("boons")))
      ).get());

result, _ := client.Query(f.CreateClass(f.Obj{"name": "boons"}))

fmt.Println(result)

client.query(CreateClass(Obj("name" -> "boons")))

client.query(q.create_class({"name": "boons"}))

$client.query do
  create_class name: 'boons'
end

client.query(CreateClass(Obj("name" => "boons")))

client.query(q.CreateClass({ name: "boons" }))
  .then((ret) => console.log(ret))

=> HTTP/1.1 201 Created
{
  "resource": {
    "ref": { "@ref": "classes/boons" },
    "class": { "@ref": "classes" },
    "ts": 1509244539971619,
    "history_days": 30,
    "name": "boons"
  }
}

=> {
  "ref": { "@ref": "classes/boons" },
  "class": { "@ref": "classes" },
  "ts": 1509244539971619,
  "history_days": 30,
  "name": "boons"
}

=> {
  ref: ref(id = "boons", class = ref(id = "classes")),
  ts: 1526674566802938,
  history_days: 30,
  name: "boons"
}

=> map[ref:{boons 0xc4201f2fa0 <nil>} ts:1527277025406385 history_days:30 name:boons]

=> {
  "ref": { "@ref": "classes/boons" },
  "class": { "@ref": "classes" },
  "ts": 1509244539971619,
  "history_days": 30,
  "name": "boons"
}

=> {
  "ref": { "@ref": "classes/boons" },
  "class": { "@ref": "classes" },
  "ts": 1509244539971619,
  "history_days": 30,
  "name": "boons"
}

=> {
  "ref": { "@ref": "classes/boons" },
  "class": { "@ref": "classes" },
  "ts": 1509244539971619,
  "history_days": 30,
  "name": "boons"
}

=> {
  "ref": { "@ref": "classes/boons" },
  "class": { "@ref": "classes" },
  "ts": 1509244539971619,
  "history_days": 30,
  "name": "boons"
}

=> { ref: Ref(id=boons, class=Ref(id=classes)),
  ts: 1527274777496292,
  history_days: 30,
  name: 'boons' }

Related References

CreateDatabase


CreateDatabase( param_object )

CreateDatabase( param_object )

CreateDatabase( param_object )

CreateDatabase( param_object )

create_database( param_object )

create_database param_object

CreateDatabase( param_object )

CreateDatabase( param_object )

Description

The CreateDatabase function adds a new database to the cluster with the specified parameters.

It requires an admin key for authentication.

Parameters

Argument Type Definition and Requirements
param_object Object The param_object fields are described below.

param_object

Field Name Field Type Definition and Requirements
name String The name of a database. Databases cannot be named any of the following reserved words: events, set, self, instances, or “_”.
data Object Optional - This is user-defined metadata for the database. It is provided for the developer to store information at the database level.
api_version Number Optional - The default client driver API version for the requests made to this database. Defaults to “2.0”
priority Long Optional - A relative weight between 1 and 500, inclusive, indicating how many resources this database will be allowed to utilize. Defaults to 1. A higher number means more resources.

Returns

An object containing the metadata of CreateDatabase operations.

Field Name Field Type Definition and Requirements
ref Reference The reference is an automatically generated unique identifier for the database that was created.
name String The name of the database just created.
ts Long The timestamp associated with the creation of the instance.

Examples

The query below creates a database named “db-next” and returns the reference to the database, the name of the database, and the time the database was created.


curl https://db.fauna.com/ \
    -u fnAChGwBacACAEZtRZFDXpyjIvq-sln34m-va4Km: \
    -d '{ "create_database": { "object": { "name": "db-next" } } }'

client.Query(CreateDatabase(Obj("name", "db-next")));

System.out.println(
      client.query(
            CreateDatabase(Obj("name", Value("db-next")))
      ).get());

result, _ := client.Query(f.CreateDatabase(f.Obj{"name": "db-next"}))

fmt.Println(result)

client.query(CreateDatabase(Obj("name" -> "db-next")))

client.query(q.create_database({"name": "db-next"}))

$client.query do
  create_database name: 'db-next'
end

client.query(CreateDatabase(Obj("name" => "db-next")))

client.query(q.CreateDatabase({ name: "db-next" }))
  .then((ret) => console.log(ret))

=> HTTP/1.1 201 Created
{
  "resource": {
    "ref": { "@ref": "databases/db-next" },
    "class": { "@ref": "databases" },
    "ts": 1509244539938619,
    "name": "db-next"
  }
}

=> {
  "ref": { "@ref": "databases/db-next" },
  "class": { "@ref": "databases" },
  "ts": 1509244539938619,
  "name": "db-next"
}

=> {
  ref: ref(id = "db-next", class = ref(id = "databases")),
  ts: 1526674566784752,
  name: "db-next"
}

=> map[ref:{db-next 0xc42021caa0 <nil>} ts:1509244539938619 name:db-next]

=> {
  "ref": { "@ref": "databases/db-next" },
  "class": { "@ref": "databases" },
  "ts": 1509244539938619,
  "name": "db-next"
}

=> {
  "ref": { "@ref": "databases/db-next" },
  "class": { "@ref": "databases" },
  "ts": 1509244539938619,
  "name": "db-next"
}

=> {
  "ref": { "@ref": "databases/db-next" },
  "class": { "@ref": "databases" },
  "ts": 1509244539938619,
  "name": "db-next"
}

=> {
  "ref": { "@ref": "databases/db-next" },
  "class": { "@ref": "databases" },
  "ts": 1509244539938619,
  "name": "db-next"
}

=> { ref: Ref(id=db-next, class=Ref(id=databases)),
  ts: 1527274824500534,
  name: 'db-next' }

Related References

CreateFunction


// Not available in this language yet.

CreateFunction( param_object )

CreateFunction( param_object )

// Not available in this language yet.

# Not available in this language yet.

# Not available in this language yet.

// Not available in this language yet.

CreateFunction( param_object )

Description

The CreateFunction operation adds a new user-defined function with the specified parameters.

Parameters

Argument Type Definition and Requirements
param_object Object The param_object fields are described below.

param_object

Field Name Field Type Definition and Requirements
name String The logical name of the function.
body Object The fauna SQL instructions to be executed.
data Object Optional - This is user-defined metadata for the user-defined function. It is provided for the developer to store information at the function level.

Returns

An object containing the metadata of CreateFunction operations.

Field Name Field Type Definition and Requirements
ref Reference The reference is an automatically generated unique identifier within the database to identify the function that was created.
name String The logical name of the function created.
ts Long The timestamp associated with the creation of the function.
body Object The Fauna SQL instructions to be executed.

Examples

The query below creates a user-defined function called “double”.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{
          "create_function": {
            "object": {
              "name": "double",
              "body": {
                "query": {
                  "lambda": "x",
                  "expr": { "add": [ { "var": "x" }, { "var": "x" } ] }
                }
              }
            }
          }
        }'

// Not available in this language yet.

System.out.println(
   client.query(
      CreateFunction(
         Obj( "name", Value("double"),
            "body" , Query(Lambda(Value("x"), Add(Var("x"), Var("x"))))
         )
      )
   ).get()); 

result, _ := client.Query(
    f.CreateFunction(f.Obj{
        "name": "double",
        "body": f.Query(f.Lambda("x", f.Add(f.Var("x"), f.Var("x")))),
    }),
)

fmt.Println(result)

client.query(
   CreateFunction(
      Obj( "name", Value("double"),
         "body" , Query(Lambda(Value("x"), Add(Var("x"), Var("x"))))
      )
   )
).get(); 

# Not available in this language yet.

# Not available in this language yet.

// Not available in this language yet.

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))

=> HTTP/1.1 201 Created
{
  "resource": {
    "ref": { "@ref": "functions/double" },
    "class": { "@ref": "functions" },
    "ts": 1509244540046619,
    "name": "double",
    "body": {
      "@query": {
        "lambda": "x",
        "expr": { "add": [ { "var": "x" }, { "var": "x" } ] }
      }
    }
  }
}

=> {
  "ref": { "@ref": "functions/double" },
  "class": { "@ref": "functions" },
  "ts": 1509244540046619,
  "name": "double",
  "body": {
    "@query": {
      "lambda": "x",
      "expr": { "add": [ { "var": "x" }, { "var": "x" } ] }
    }
  }
}

=> {
  ref: ref(id = "double", class = ref(id = "functions")),
  ts: 1527869785204010,
  name: "double",
  body: QueryV({lambda=x, expr={add=[{var=x}, {var=x}]}})
}

=> map[
  ref:{double 0xc4202310a0 <nil>}
  ts:1509244540046619
  body:{[123 34 108 97 109 98 100 97 34 58 34 120 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 120 34 125 44 123 34 118 97 114 34 58 34 120 34 125 93 125 125]}
]

=> {
  "ref": { "@ref": "functions/double" },
  "class": { "@ref": "functions" },
  "ts": 1509244540046619,
  "name": "double",
  "body": {
    "@query": {
      "lambda": "x",
      "expr": { "add": [ { "var": "x" }, { "var": "x" } ] }
    }
  }
}

=> {
  "ref": { "@ref": "functions/double" },
  "class": { "@ref": "functions" },
  "ts": 1509244540046619,
  "name": "double",
  "body": {
    "@query": {
      "lambda": "x",
      "expr": { "add": [ { "var": "x" }, { "var": "x" } ] }
    }
  }
}

=> {
  "ref": { "@ref": "functions/double" },
  "class": { "@ref": "functions" },
  "ts": 1509244540046619,
  "name": "double",
  "body": {
    "@query": {
      "lambda": "x",
      "expr": { "add": [ { "var": "x" }, { "var": "x" } ] }
    }
  }
}

=> {
  "ref": { "@ref": "functions/double" },
  "class": { "@ref": "functions" },
  "ts": 1509244540046619,
  "name": "double",
  "body": {
    "@query": {
      "lambda": "x",
      "expr": { "add": [ { "var": "x" }, { "var": "x" } ] }
    }
  }
}

=> { ref: Ref(id=double, class=Ref(id=functions)),
  ts: 1527275011179623,
  name: 'double',
  body: Query("[object Object]") }

Related References

CreateIndex


CreateIndex( param_object )

CreateIndex( param_object )

CreateIndex( param_object )

CreateIndex( param_object )

create_index( param_object )

create_index param_object

CreateIndex( param_object )

CreateIndex( param_object )

Description

The CreateIndex function adds a new index to the cluster with the specified parameters. After the transaction containing the CreateIndex is completed, the index is immediately available for reads. (The index may not be used in the transaction it was created.) The index may return incomplete results until it is fully built and marked as active. FaunaDB will asynchronously build the index by scanning over relevant instance objects of the source class(es).

Updating index fields
  • It is possible to rename an index by updating its name field. Renaming an index changes its reference, but preserves inbound references to the index. Index data is not rebuilt.
  • If you update the unique field, it will not remove existing duplicated items from the index, but will prevent future duplicates from being added.
  • The fields of an index which may not be modified are: terms, values, or partitions.

When an index is deleted, it becomes inaccessible, and its data is deleted asynchronously.

Parameters

Argument Type Definition and Requirements
param_object Object The param_object fields are described below.

param_object

Field Name Field Type Definition and Requirements
name String The logical name of the index. Cannot be events, sets, self, instances, or _.
source VarArgs One or more source objects describing source classes and (optional) fields.
terms Array Optional - An array of term objects describing the fields to be indexed.
values Array Optional - An array of value objects describing the fields to be covered.
unique Boolean Optional - If true, maintains a unique constraint on combined terms and values.
serialized Boolean Optional - If true, writes to this index are serialized with concurrent reads and writes.
partitions Integer Optional - The number of sub-partitions within each term.
permissions Object Optional - Indicates who is allowed to read the index.
data Object Optional - This is user-defined metadata for the index. It is provided for the developer to store information at the index level.

Returns

An object containing the metadata about the CreateIndex operations.

Field Name Field Type Definition and Requirements
ref Reference The reference is an automatically generated unique identifier within the database to the index that was created.
name String The logical name of the index created.
source VarArgs The source and binding of the newly created index.
ts Long The timestamp associated with the creation of the index.
active Boolean Indicates if the index has completed building and is fully operational.
partitions Long The timestamp associated with the creation of the index.

Examples

The CreateIndex operation builds an index on the class “spells” with the name “new-index”.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{
          "create_index": {
            "object": { "name": "new-index", "source": { "class": "spells" } }
          }
        }'

client.Query(
  CreateIndex(
    Obj("name", "new-index", "source", Class("spells"))));

System.out.println(
      client.query(
          CreateIndex(
              Obj(
                  "name", Value("new-index"),
                  "source", Class(Value("spells"))
              )
          )
      ).get());

result, _ := client.Query(
    f.CreateIndex(
        f.Obj{"name": "new-index", "source": f.Class("spells")},
    ),
)

fmt.Println(result)

client.query(
  CreateIndex(
    Obj("name" -> "new-index", "source" -> Class("spells"))))

client.query(
  q.create_index(
    {"name": "new-index", "source": q.class_expr("spells")}
  ))

$client.query do
  create_index name: 'new-index', source: class_('spells')
end

client.query(
    CreateIndex(
        Obj("name" => "new-index", "source" => Class("spells"))
    )
)

client.query(
  q.CreateIndex(
    { name: "new-index", source: q.Class("spells") }))
.then((ret) => console.log(ret))

=> HTTP/1.1 201 Created
{
  "resource": {
    "ref": { "@ref": "indexes/new-index" },
    "class": { "@ref": "indexes" },
    "ts": 1509244540009619,
    "active": false,
    "partitions": 8,
    "name": "new-index",
    "source": { "@ref": "classes/spells" }
  }
}

=> {
  "ref": { "@ref": "indexes/new-index" },
  "class": { "@ref": "indexes" },
  "ts": 1509244540009619,
  "active": false,
  "partitions": 8,
  "name": "new-index",
  "source": { "@ref": "classes/spells" }
}

=> {
  ref: ref(id = "new-index", class = ref(id = "indexes")),
  ts: 1526674566835735,
  active: false,
  partitions: 8,
  name: "new-index",
  source: ref(id = "spells", class = ref(id = "classes"))
}

=> map[ref:{new-index 0xc4201ef8e0 <nil>} ts:1509244540009619 active:false partitions:8 name:new-index source:{spells 0xc4201efb40 <nil>}]

=> {
  "ref": { "@ref": "indexes/new-index" },
  "class": { "@ref": "indexes" },
  "ts": 1509244540009619,
  "active": false,
  "partitions": 8,
  "name": "new-index",
  "source": { "@ref": "classes/spells" }
}

=> {
  "ref": { "@ref": "indexes/new-index" },
  "class": { "@ref": "indexes" },
  "ts": 1509244540009619,
  "active": false,
  "partitions": 8,
  "name": "new-index",
  "source": { "@ref": "classes/spells" }
}

=> {
  "ref": { "@ref": "indexes/new-index" },
  "class": { "@ref": "indexes" },
  "ts": 1509244540009619,
  "active": false,
  "partitions": 8,
  "name": "new-index",
  "source": { "@ref": "classes/spells" }
}

=> {
  "ref": { "@ref": "indexes/new-index" },
  "class": { "@ref": "indexes" },
  "ts": 1509244540009619,
  "active": false,
  "partitions": 8,
  "name": "new-index",
  "source": { "@ref": "classes/spells" }
}

=> { ref: Ref(id=new-index, class=Ref(id=indexes)),
  ts: 1527275052756370,
  active: false,
  partitions: 8,
  name: 'new-index',
  source: Ref(id=spells, class=Ref(id=classes)) }

Related References

CreateKey


CreateKey( param_object )

CreateKey( param_object )

CreateKey( param_object )

CreateKey( param_object )

create_key( param_object )

create_key param_object

CreateKey( param_object )

CreateKey( param_object )

Description

CreateKey creates a new key to access a database with the specified param_object. It requires an admin key for authentication.

Parameters

Argument Type Definition and Requirements
param_object Object The param_object fields are described below.

param_object

Field Name Field Type Definition and Requirements
database String The logical name of an existing database.
role String The access roles include admin, server, server-readonly, or client.
priority Number Optional - A relative weight between 1 and 500, inclusive, indicating how many resources this key will be allowed to utilize. Defaults to 1. A higher number means more resources
data Object Optional - This is user-defined metadata for the key. It is provided for the developer to store information at the key level.

Returns

An object containing the metadata about the results of CreateKey operations.

Field Name Field Type Definition and Requirements
ref Reference The reference is an automatically generated unique identifier within the database to the key that was created.
database String The name of the database the key belongs to.
role String The access role for this key.
ts Long The timestamp associated with the creation of the index.
secret String The key’s authentication secret. It is only present at creation. You must copy the key’s secret and store it securely for future use.
hashed_secret String The key’s hashed authentication secret.

Examples

The query below creates a key for the “prydian” database with an access role of server.


curl https://db.fauna.com/ \
    -u fnAChGwBacACAEZtRZFDXpyjIvq-sln34m-va4Km: \
    -d '{
          "create_key": {
            "object": { "database": { "database": "prydain" }, "role": "server" }
          }
        }'

client.Query(
  CreateKey(
    Obj("database", Database("prydain"), "role", "server")));

System.out.println(
      client.query(
          CreateKey(
              Obj(
                 "database", Database(Value("prydain")),
                 "role", Value("server")
              ))
        ).get());

result, _ := client.Query(
    f.CreateKey(
        f.Obj{"database": f.Database("prydain"), "role": "server"},
    ),
)

fmt.Println(result)

client.query(
  CreateKey(
    Obj("database" -> Database("prydain"), "role" -> "server")))

client.query(
  q.create_key(
    {"database": q.database("prydain"), "role": "server"}
  ))

$client.query do
  create_key database: database('prydain'), role: 'server'
end

client.query(
    CreateKey(
        Obj(
            "database" => Database("prydain"),
            "role" => "server"
        )
    )
)

client.query(
  q.CreateKey(
    { database: q.Database("prydain"), role: "server" }))
.then((ret) => console.log(ret))

=> HTTP/1.1 201 Created
{
  "resource": {
    "ref": { "@ref": "keys/181388642789360128" },
    "class": { "@ref": "keys" },
    "ts": 1509244539905476,
    "database": { "@ref": "databases/prydain" },
    "role": "server",
    "secret": "fnAChGwCc8ACAJ14XId4jxQlr2sn496g1J7Ysq42",
    "hashed_secret": "$2a$05$xVX/E8zRRLTPgRvVGacOJOVUDa9UdaY9wTGoDOCbqoLQj9yJHwNsO"
  }
}

=> {
  "ref": { "@ref": "keys/181388642789360128" },
  "class": { "@ref": "keys" },
  "ts": 1509244539905476,
  "database": { "@ref": "databases/prydain" },
  "role": "server",
  "secret": "fnAChGwCc8ACAJ14XId4jxQlr2sn496g1J7Ysq42",
  "hashed_secret": "$2a$05$xVX/E8zRRLTPgRvVGacOJOVUDa9UdaY9wTGoDOCbqoLQj9yJHwNsO"
}

=> {
  ref: ref(id = "199665350603702784", class = ref(id = "keys")),
  ts: 1526674566735005,
  database: ref(id = "prydain", class = ref(id = "databases")),
  role: "server",
  secret: "fnACxVqUGLACAMdiPcGMWvtTPn__pBKRjqwjkj38",
  hashed_secret: "$2a$05$bwfQwJxBr468C15NHM37KOo4krZbdvxiEXyDZ6Xll6DN5MhAjSvqa"
}

=> map[ref:{181388642789360128 0xc4201c3a40 <nil>} ts:1509244539905476 database:{prydain 0xc4201c3be0 <nil>} role:server secret:fnAChGwCc8ACAJ14XId4jxQlr2sn496g1J7Ysq42 hashed_secret:$2a$05$xVX/E8zRRLTPgRvVGacOJOVUDa9UdaY9wTGoDOCbqoLQj9yJHwNsO]

=> {
  "ref": { "@ref": "keys/181388642789360128" },
  "class": { "@ref": "keys" },
  "ts": 1509244539905476,
  "database": { "@ref": "databases/prydain" },
  "role": "server",
  "secret": "fnAChGwCc8ACAJ14XId4jxQlr2sn496g1J7Ysq42",
  "hashed_secret": "$2a$05$xVX/E8zRRLTPgRvVGacOJOVUDa9UdaY9wTGoDOCbqoLQj9yJHwNsO"
}

=> {
  "ref": { "@ref": "keys/181388642789360128" },
  "class": { "@ref": "keys" },
  "ts": 1509244539905476,
  "database": { "@ref": "databases/prydain" },
  "role": "server",
  "secret": "fnAChGwCc8ACAJ14XId4jxQlr2sn496g1J7Ysq42",
  "hashed_secret": "$2a$05$xVX/E8zRRLTPgRvVGacOJOVUDa9UdaY9wTGoDOCbqoLQj9yJHwNsO"
}

=> {
  "ref": { "@ref": "keys/181388642789360128" },
  "class": { "@ref": "keys" },
  "ts": 1509244539905476,
  "database": { "@ref": "databases/prydain" },
  "role": "server",
  "secret": "fnAChGwCc8ACAJ14XId4jxQlr2sn496g1J7Ysq42",
  "hashed_secret": "$2a$05$xVX/E8zRRLTPgRvVGacOJOVUDa9UdaY9wTGoDOCbqoLQj9yJHwNsO"
}

=> {
  "ref": { "@ref": "keys/181388642789360128" },
  "class": { "@ref": "keys" },
  "ts": 1509244539905476,
  "database": { "@ref": "databases/prydain" },
  "role": "server",
  "secret": "fnAChGwCc8ACAJ14XId4jxQlr2sn496g1J7Ysq42",
  "hashed_secret": "$2a$05$xVX/E8zRRLTPgRvVGacOJOVUDa9UdaY9wTGoDOCbqoLQj9yJHwNsO"
}

=> { ref: Ref(id=200295040051839490, class=Ref(id=keys)),
  ts: 1527275085327966,
  database: Ref(id=prydain, class=Ref(id=databases)),
  role: 'server',
  secret: 'fnACx5dHGJACAvbi1rpiKJFPsvWEdwvJjmEllT1q',
  hashed_secret:
   '$2a$05$cNALKjEyHHbx5XcxdQDd1uFlg9w7ILiGCkPiOBm.GkqdRvqLYTJpe' }

Related References

Delete


Delete( ref )

Delete( ref )

Delete( ref )

Delete( ref )

delete( ref )

delete ref

Delete( ref )

Delete( ref )

Description

The delete function removes an object. Some of the common objects to delete are instances, classes, indexes and databases.

Parameters

Argument Type Definition and Requirements
ref Reference The reference to an object that was removed.

Returns

An object containing the metadata about the delete operations.

Field Name Field Type Definition and Requirements
database String The logical name of an existing database.
role String The access roles include admin, server, server-readonly, or client.
data Object Optional - This is user-defined metadata for the key. It is provided for the developer to store information at the key level.
priority Long Optional - A relative weight between 1 and 500, inclusive, indicating how many resources this database will be allowed to utilize. Defaults to 1. A higher number means more resources.

Examples

The query below removes the instance data pointed at by the reference.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "delete": { "@ref": "classes/spells/181388642581742080" } }'

client.Query(Delete(Ref("classes/spells/181388642581742080")));

System.out.println(
        client.query(
                Delete(Ref(Class("spells"), Value(181388642581742080L)))
        ).get());

result, _ := client.Query(
    f.Delete(f.RefClass(f.Class("spells"), "181388642581742080")),
)

fmt.Println(result)

client.query(Delete(Ref("classes/spells/181388642581742080")))

client.query(q.delete(Ref("classes/spells/181388642581742080")))

$client.query do
  delete ref('classes/spells/181388642581742080')
end

client.query(
    Delete(ref: Ref("classes/spells/181388642581742080"))
)

client.query(q.Delete(q.Ref(q.Class("spells"), "181388642581742080")))
  .then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{
  "resource": {
    "ref": { "@ref": "classes/spells/181388642581742080" },
    "class": { "@ref": "classes/spells" },
    "ts": 1509244539764856,
    "data": {
      "name": "Mountain's Thunder",
      "element": [ "air", "earth" ],
      "cost": 10
    }
  }
}

=> {
  "ref": { "@ref": "classes/spells/181388642581742080" },
  "class": { "@ref": "classes/spells" },
  "ts": 1509244539764856,
  "data": {
    "name": "Mountain's Thunder",
    "element": [ "air", "earth" ],
    "cost": 10
  }
}

=> {
  ref: ref(id = "181388642581742080", class = ref(id = "spells", class = ref(id = "classes"))),
  ts: 1509244539764856,
  data: {
    name: "Mountain's Thunder",
    element: ["air", "earth"],
    cost: 10
  }
}

=> map[ref:{181388642581742080 0xc4201f3da0 <nil>} ts:1509244539764856 data:map[cost:10 element:[air earth] name:Mountain's Thunder]]

=> {
  "ref": { "@ref": "classes/spells/181388642581742080" },
  "class": { "@ref": "classes/spells" },
  "ts": 1509244539764856,
  "data": {
    "name": "Mountain's Thunder",
    "element": [ "air", "earth" ],
    "cost": 10
  }
}

=> {
  "ref": { "@ref": "classes/spells/181388642581742080" },
  "class": { "@ref": "classes/spells" },
  "ts": 1509244539764856,
  "data": {
    "name": "Mountain's Thunder",
    "element": [ "air", "earth" ],
    "cost": 10
  }
}

=> {
  "ref": { "@ref": "classes/spells/181388642581742080" },
  "class": { "@ref": "classes/spells" },
  "ts": 1509244539764856,
  "data": {
    "name": "Mountain's Thunder",
    "element": [ "air", "earth" ],
    "cost": 10
  }
}

=> {
  "ref": { "@ref": "classes/spells/181388642581742080" },
  "class": { "@ref": "classes/spells" },
  "ts": 1509244539764856,
  "data": {
    "name": "Mountain's Thunder",
    "element": [ "air", "earth" ],
    "cost": 10
  }
}

=> { ref:
   Ref(id=181388642581742080, class=Ref(id=spells, class=Ref(id=classes))),
  ts: 1527275280180078,
  data:
   { name: 'Mountain\'s Thunder',
     element: [ 'air', 'earth' ],
     cost: 10 } }

Related References

Insert

insert (ref, ts, action, param_object)

Description

The insert operation adds an event to an instance’s history at a specified timestamp.

Parameters

Argument Type Definition and Requirements
ref Reference A reference must refer to a user-defined class or a key to be modified. A reference to any other class will result in an “invalid argument” error.
ts Long The time when the instance’s history will be modified. Can be expressed as either a number of UNIX microseconds or as a time value.
action String The type of action (create, delete, update) to be added.
param_object Object The param_object is an object which can contain many items.

param_object

Field Name Field Type Definition and Requirements
data Object The instance’s user data to be modified.
credentials Object The instance’s credentials to be modified.
delegates Object The instance’s delegates to be modified.

Returns

An object containing the metadata about the insert operations.

Field Name Field Type Definition and Requirements
ts Long The time when the instance’s history will be modified.
action String The timestamp associated with the removal of the data.
instance Reference The reference which identifies the instance’s history was updated.
data Object A copy of the instance data which was removed.

Examples

The query modifies the history of the “spells” class for the instance at id 181388642581742080, adding an instance create operation at timestamp 1 with the associated user data.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{
          "insert": { "@ref": "classes/spells/181388642581742080" },
          "ts": 1,
          "action": "create",
          "params": {
            "object": {
              "data": {
                "object": {
                  "name": "Mountain's Thunder",
                  "cost": 10,
                  "element": [ "air", "earth" ]
                }
              }
            }
          }
        }'

client.Query(
  Insert(
    Ref("classes/spells/181388642581742080"),
    ts: 1,
    action: "create",
    @params: Obj(
      "data", Obj(
        "name", "Mountain's Thunder",
        "cost", 10,
        "element", Arr("air", "earth")
      )
    )));

System.out.println(
    client.query(
       Insert(
           Ref(Class("spells"), Value(181388642581742080L)),
           Value(1),
           Action.CREATE,
           Obj(
              "data", Obj(
                      "name", Value("Mountain's Thunder"),
                      "cost", Value(10),
                      "element", Arr(Value("air"), Value("earth"))
                      )
           )
       )
    ).get());

result, _ := client.Query(
    f.Insert(
        f.RefClass(f.Class("spells"), "181388642581742080"),
        1,
        f.ActionCreate,
        f.Obj{
            "data": f.Obj{
                "name": "Mountain's Thunder",
                "cost": 10,
                "element": f.Arr{"air", "earth"},
            },
        },
    ),
)

fmt.Println(result)

client.query(
  Insert(
    Ref("classes/spells/181388642581742080"),
    ts = 1,
    action = "create",
    params = Obj(
      "data" -> Obj(
        "name" -> "Mountain's Thunder",
        "cost" -> 10,
        "element" -> Arr("air", "earth")
      )
    )))

client.query(
  q.insert(
    Ref("classes/spells/181388642581742080"),
    ts=1,
    action="create",
    params={
      "data": {
        "name": "Mountain's Thunder",
        "cost": 10,
        "element": ["air", "earth"]
      }
    }
  ))

$client.query do
  insert ref('classes/spells/181388642581742080'),
         1,
         'create',
         data: {
           name: "Mountain's Thunder",
           cost: 10,
           element: ['air', 'earth']
         }
end

client.query(
    Insert(
        ref: Ref("classes/spells/181388642581742080"),
        ts: 1,
        action: "create",
        params: Obj(
            "data" => Obj(
                "name" => "Mountain's Thunder",
                "cost" => 10,
                "element" => Arr("air", "earth")
            )
        )
    )
)

client.query(
  q.Insert(q.Ref(q.Class("spells"), "181388642581742080"), 1, "create", { data: {
    name: "Mountain's Thunder",
    cost: 10,
    element: ["air", "earth"]
  }}))
.then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{
  "resource": {
    "ts": 1,
    "action": "create",
    "resource": { "@ref": "classes/spells/181388642581742080" }
  }
}

=> {
  "ts": 1,
  "action": "create",
  "resource": { "@ref": "classes/spells/181388642581742080" }
}

=> {
  ts: 1,
  action: "create"
  instance: ref(id = "181388642581742080", class = ref(id = "spells", class = ref(id = "classes"))),
  data: {
    name: "Mountain's Thunder",
    cost: 10,
    element: ["air", "earth"]
  }
}

=> map[ts:1 action:create instance:{181388642581742080 0xc420254480 <nil>} data:map[name:Mountain's Thunder cost:10 element:[air earth]]]

=> {
  "ts": 1,
  "action": "create",
  "resource": { "@ref": "classes/spells/181388642581742080" }
}

=> {
  "ts": 1,
  "action": "create",
  "resource": { "@ref": "classes/spells/181388642581742080" }
}

=> {
  "ts": 1,
  "action": "create",
  "resource": { "@ref": "classes/spells/181388642581742080" }
}

=> {
  "ts": 1,
  "action": "create",
  "resource": { "@ref": "classes/spells/181388642581742080" }
}

=> { ts: 1,
  action: 'create',
  instance:
   Ref(id=181388642581742080, class=Ref(id=spells, class=Ref(id=classes))),
  data:
   { name: 'Mountain\'s Thunder',
     cost: 10,
     element: [ 'air', 'earth' ] } }

Related References

Remove


Remove(Ref,TS, Action)

Remove(Ref, TS, Action)

Remove(Ref, TS, Action)

Remove(Ref, TS, Action)

remove(Ref, TS, Action)

remove(Ref, TS, Action)

Remove(Ref, TS, Action)

Remove(Ref, TS, Action)

Description

The remove function deletes an event from an instance’s history. The reference must refer to an instance of a user-defined class.

Outstanding references result in an “invalid argument” error.

Parameters

Argument Type Definition and Requirements
ref Reference A reference type containing the instance that will be modified.
ts Long The time when the instance’s history will be modified. Can be expressed as either a number of UNIX microseconds or as a time value.
action Instance Action The type of action (create, delete, update) to be modified.

Returns

An object containing the metadata of the remove operations.

Field Name Field Type Definition and Requirements
ref Reference The reference which identifies the instance updated.
data Object A copy of the new instance data.
ts Long The timestamp associated with the removal of the data.

Examples

The query below changes the history for an instance in the “spells” class. The create event at timestamp 1 will be removed.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{
          "remove": { "@ref": "classes/spells/181388642581742080" },
          "ts": 1,
          "action": "create"
        }'

client.Query(
  Remove(
    Ref("classes/spells/181388642581742080"),
    ts: 1,
    action: "create"));

System.out.println(
     client.query(
        Remove(
           Ref(Class("spells"), Value(181388642581742080L)),
           Value(1),
           Action.CREATE
        )
     ).get());

result, _ := client.Query(
    f.Remove(
        f.RefClass(f.Class("spells"), "181388642581742080"),
        1,
        f.ActionCreate,
    ),
)

fmt.Println(result)

client.query(
  Remove(
    Ref("classes/spells/181388642581742080"),
    ts = 1,
    action = "create"))

client.query(
  q.remove(
    Ref("classes/spells/181388642581742080"),
    ts=1,
    action="create"
  ))

$client.query do
  remove ref('classes/spells/181388642581742080'), 1, 'create'
end

client.query(
    Remove(
        ref: Ref("classes/spells/181388642581742080"),
        ts: 1,
        action: "create"
    )
)

client.query(q.Remove(q.Ref(q.Class("spells"), "181388642581742080"), 1, "create"))
  .then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{ "resource": null }

=> null

=> null

=> {}

=> null

=> null

=> null

=> null

=> null

Related References

Replace


Replace( ref, param_object )

Replace( ref, param_object )

Replace( ref, param_object )

Replace( ref, param_object )

replace( ref, param_object )

replace ref param_object

Replace( ref, param_object )

Replace( ref, param_object )

Description

The replace operation substitutes the user data pointed to by the reference with the data contained in the param_object. Values not specified in the param_object are removed.

Parameters

Argument Type Definition and Requirements
ref Reference A reference type containing the instance that will be modified.
param_object Object The param_object is an object which can contain many items.
param_object
Field Name Field Type Definition and Requirements
data Object The instance’s user data to be modified.

Returns

An object containing the metadata about the replace operations.

Field Name Field Type Definition and Requirements
ref Reference The reference which identifies the instance just updated.
data Object A copy of the new instance data.
ts Long The timestamp associated with the removal of the data.

Examples

The query below updates the instance data by changing the name field to the value “Mountains’s Thunder” and removing the “cost” field from the instance.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{
          "replace": { "@ref": "classes/spells/181388642581742080" },
          "params": {
            "object": {
              "data": {
                "object": {
                  "name": "Mountain's Thunder",
                  "element": [ "air", "earth" ],
                  "cost": 10
                }
              }
            }
          }
        }'

client.Query(
  Replace(
    Ref("classes/spells/181388642581742080"),
    Obj(
      "data", Obj(
        "name", "Mountain's Thunder",
        "element", Arr("air", "earth"),
        "cost", 10
      )
    )));

System.out.println(
    client.query(
        Replace(
            Ref(Class("spells"), Value(181388642581742080L)),
            Obj(
               "data", Obj(
                          "name", Value("Mountain's Thunder"),
                           "element", Arr(Value("air"), Value("earth")),
                           "cost", Value(10)
                        )
             )
          )
    ).get());

result, _ := client.Query(
    f.Replace(
        f.RefClass(f.Class("spells"), "181388642581742080"),
        f.Obj{
            "data": f.Obj{
                "name": "Mountain's Thunder",
                "element": f.Arr{"air", "earth"},
                "cost": 10,
            },
        },
    ),
)

fmt.Println(result)

client.query(
  Replace(
    Ref("classes/spells/181388642581742080"),
    Obj(
      "data" -> Obj(
        "name" -> "Mountain's Thunder",
        "element" -> Arr("air", "earth"),
        "cost" -> 10
      )
    )))

client.query(
  q.replace(
    Ref("classes/spells/181388642581742080"),
    {
      "data": {
        "name": "Mountain's Thunder",
        "element": ["air", "earth"],
        "cost": 10
      }
    }
  ))

$client.query do
  replace ref('classes/spells/181388642581742080'),
          data: {
            name: "Mountain's Thunder",
            element: ['air', 'earth'],
            cost: 10
          }
end

client.query(
    Replace(
        ref: Ref("classes/spells/181388642581742080"),
        with: Obj(
            "data" => Obj(
                "name" => "Mountain's Thunder",
                "element" => Arr("air", "earth"),
                "cost" => 10
            )
        )
    )
)

client.query(q.Replace(q.Ref(q.Class("spells"), "181388642581742080"), { data: {
  name: "Mountain's Thunder",
  element: ["air", "earth"],
  cost: 10
}}))
.then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{
  "resource": {
    "ref": { "@ref": "classes/spells/181388642581742080" },
    "class": { "@ref": "classes/spells" },
    "ts": 1509244539764856,
    "data": {
      "name": "Mountain's Thunder",
      "element": [ "air", "earth" ],
      "cost": 10
    }
  }
}

=> {
  "ref": { "@ref": "classes/spells/181388642581742080" },
  "class": { "@ref": "classes/spells" },
  "ts": 1509244539764856,
  "data": {
    "name": "Mountain's Thunder",
    "element": [ "air", "earth" ],
    "cost": 10
  }
}

=> {
  ref: ref(id = "181388642581742080", class = ref(id = "spells", class = ref(id = "classes"))),
  ts: 1526674566665295,
  data: {
    name: "Mountain's Thunder", 
    element: ["air", "earth"], 
    cost: 10
  }
}

=> map[ref:{181388642581742080 0xc420237480 <nil>} ts:1509244539764856 data:map[cost:10 element:[air earth] name:Mountain's Thunder]]

=> {
  "ref": { "@ref": "classes/spells/181388642581742080" },
  "class": { "@ref": "classes/spells" },
  "ts": 1509244539764856,
  "data": {
    "name": "Mountain's Thunder",
    "element": [ "air", "earth" ],
    "cost": 10
  }
}

=> {
  "ref": { "@ref": "classes/spells/181388642581742080" },
  "class": { "@ref": "classes/spells" },
  "ts": 1509244539764856,
  "data": {
    "name": "Mountain's Thunder",
    "element": [ "air", "earth" ],
    "cost": 10
  }
}

=> {
  "ref": { "@ref": "classes/spells/181388642581742080" },
  "class": { "@ref": "classes/spells" },
  "ts": 1509244539764856,
  "data": {
    "name": "Mountain's Thunder",
    "element": [ "air", "earth" ],
    "cost": 10
  }
}

=> {
  "ref": { "@ref": "classes/spells/181388642581742080" },
  "class": { "@ref": "classes/spells" },
  "ts": 1509244539764856,
  "data": {
    "name": "Mountain's Thunder",
    "element": [ "air", "earth" ],
    "cost": 10
  }
}

=> { ref:
   Ref(id=181388642581742080, class=Ref(id=spells, class=Ref(id=classes))),
  ts: 1527275958680623,
  data:
   { name: 'Mountain\'s Thunder',
     element: [ 'air', 'earth' ],
     cost: 10 } }

Related References

Replacing Posts

Update


Update( ref, param_object )

Update( ref, param_object )

Update( ref, param_object )

Update( ref param_object )

q.update( ref param_object )

update ref param_object

Update( ref param_object )

Update( ref, param_object )

Description

The update operation only modifies the specified fields in the instances pointed to by ref. Updates are partial, and only modify values that are specified in the param_object. Changes to scalar values and arrays are entirely replaced by the new data. Modifications to objects are merged. Setting a value to null will completely remove the value. Fields in the instance not specified in the param_object will not be modified.

Parameters

Argument Type Definition and Requirements
ref Reference A reference type containing the instance that will be modified.
param_object Object The param_object is an object which can contain many items.

param_object

Field Name Field Type Definition and Requirements
data Object The instance’s user data to be modified.
credentials Object The instance’s credentials to be modified.
delegates Object The instance’s delegates to be modified.

Returns

An object containing the metadata about the update operations.

Field Name Field Type Definition and Requirements
ref Reference The reference which identifies the instance just updated.
data Object A copy of the new instance data.
ts Long The timestamp associated with the removal of the data.

Examples

The query below updates the instance data by changing the “name” field to the value “Mountains’s Thunder” and removing the “cost” field from the instance. All other fields in the instance will remain unchanged.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{
          "update": { "@ref": "classes/spells/181388642581742080" },
          "params": {
            "object": {
              "data": {
                "object": { "name": "Mountain's Thunder", "cost": null }
              }
            }
          }
        }'

client.Query(
  Update(
    Ref("classes/spells/181388642581742080"),
    Obj("data", Obj("name", "Mountain's Thunder", "cost", Null()))));

System.out.println(
    client.query(
        Update(
           Ref(Class("spells"), Value(181388642581742080L)),
           Obj(
              "data", Obj(
                  "name", Value("Mountain's Thunder"),
                  "cost", Null()
              )
           )
        )
    ).get());

result, _ := client.Query(
    f.Update(
        f.RefClass(f.Class("spells"), "181388642581742080"),
        f.Obj{
            "data": f.Obj{"name": "Mountain's Thunder", "cost": f.Null()},
        },
    ),
)

fmt.Println(result)

client.query(
  Update(
    Ref("classes/spells/181388642581742080"),
    Obj(
      "data" -> Obj("name" -> "Mountain's Thunder", "cost" -> Null())
    )))

client.query(
  q.update(
    Ref("classes/spells/181388642581742080"),
    {"data": {"name": "Mountain's Thunder", "cost": None}}
  ))

$client.query do
  update ref('classes/spells/181388642581742080'),
         data: { name: "Mountain's Thunder", cost: nil }
end

client.query(
    Update(
        ref: Ref("classes/spells/181388642581742080"),
        to: Obj(
            "data" => Obj("name" => "Mountain's Thunder", "cost" => nil)
        )
    )
)

client.query(q.Update(q.Ref(q.Class("spells"), "181388642581742080"), { data: {
  name: "Mountain's Thunder", cost: null } }))
.then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{
  "resource": {
    "ref": { "@ref": "classes/spells/181388642581742080" },
    "class": { "@ref": "classes/spells" },
    "ts": 1509244539727423,
    "data": { "name": "Mountain's Thunder", "element": "air" }
  }
}

=> {
  "ref": { "@ref": "classes/spells/181388642581742080" },
  "class": { "@ref": "classes/spells" },
  "ts": 1509244539727423,
  "data": { "name": "Mountain's Thunder", "element": "air" }
}

=> {
   ref: ref(id = "181388642581742080", class = ref(id = "spells", class = ref(id = "classes"))),
   ts: 1526674566645179,
   data: {
     name: "Mountain's Thunder", 
     element: "air"
   }
 }

=> map[ref:{181388642581742080 0xc420229300 <nil>} ts:1509244539727423 data:map[name:Mountain's Thunder element:air]]

=> {
  "ref": { "@ref": "classes/spells/181388642581742080" },
  "class": { "@ref": "classes/spells" },
  "ts": 1509244539727423,
  "data": { "name": "Mountain's Thunder", "element": "air" }
}

=> {
  "ref": { "@ref": "classes/spells/181388642581742080" },
  "class": { "@ref": "classes/spells" },
  "ts": 1509244539727423,
  "data": { "name": "Mountain's Thunder", "element": "air" }
}

=> {
  "ref": { "@ref": "classes/spells/181388642581742080" },
  "class": { "@ref": "classes/spells" },
  "ts": 1509244539727423,
  "data": { "name": "Mountain's Thunder", "element": "air" }
}

=> {
  "ref": { "@ref": "classes/spells/181388642581742080" },
  "class": { "@ref": "classes/spells" },
  "ts": 1509244539727423,
  "data": { "name": "Mountain's Thunder", "element": "air" }
}

=> { ref:
   Ref(id=181388642581742080, class=Ref(id=spells, class=Ref(id=classes))),
  ts: 1527276015058883,
  data: { name: 'Mountain\'s Thunder', element: [ 'air' ] } }

Related References

Updating Posts

Sets

Set functions return ad hoc set predicates based on their arguments. They can be composed to create more complex sets. The paginate function is used to access a set’s elements and historical timeline.

match(index_ref, terms)

match returns the set of instances that match the terms, based on the configuration of the specified index. terms can be either a single value, or an array.

The number of terms provided must match the number of term fields indexed by index_ref. If index_ref is configured with no terms, then terms may be omitted.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{
          "paginate": {
            "match": { "index": "spells_by_element" },
            "terms": "fire"
          }
        }'

client.Query(
  Paginate(Match(Index("spells_by_element"), "fire")));

System.out.println(
       client.query(
         Paginate(
           Match(Index(Value("spells_by_element")), Value("fire")))
       ).get());

result, _ := client.Query(
    f.Paginate(
        f.MatchTerm(f.Index("spells_by_element"), "fire"),
    ),
)

fmt.Println(result)

client.query(
  Paginate(Match(Index("spells_by_element"), "fire")))

client.query(
  q.paginate(q.match(q.index("spells_by_element"), "fire")))

$client.query do
  paginate match(index('spells_by_element'), 'fire')
end

client.query(
    Paginate(
        Match(
            index: Index("spells_by_element"),
            terms: "fire"
        )
    )
)

client.query(
  q.Paginate(q.Match(q.Index("spells_by_element"), "fire")))
.then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{
  "resource": {
    "data": [
      { "@ref": "classes/spells/181388642046968320" },
      { "@ref": "classes/spells/181388642071085568" }
    ]
  }
}

=> {
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/spells/181388642071085568" }
  ]
}

=> {
  data: [
    ref(id = "181388642046968320", class = ref(id = "spells", class = ref(id = "classes"))),
    ref(id = "181388642071085568", class = ref(id = "spells", class = ref(id = "classes")))
  ]
}

=> map[data:[{181388642046968320 0xc4202a8a00 <nil>} {181388642071085568 0xc4202a8c20 <nil>}]]

=> {
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/spells/181388642071085568" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/spells/181388642071085568" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/spells/181388642071085568" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/spells/181388642071085568" }
  ]
}

=> { data:
   [ Ref(id=181388642046968320, class=Ref(id=spells, class=Ref(id=classes))),
     Ref(id=181388642071085568, class=Ref(id=spells, class=Ref(id=classes))) ] }

The events view of match contains events for instances as they enter and exit the set over time, based on updates to the instances themselves.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{
          "paginate": {
            "match": { "index": "spells_by_element" },
            "terms": "fire"
          },
          "events": true
        }'

client.Query(
  Paginate(
    Match(Index("spells_by_element"), "fire"),
    events: true));

System.out.println(
        client.query(
           Paginate(
              Events(
                 Match(Index(Value("spells_by_element")), Value("fire"))
              )
           )
        ).get());

result, _ := client.Query(
    f.Paginate(
        f.Events(
            f.MatchTerm(f.Index("spells_by_element"), "fire"),
        ),
    ),
)

fmt.Println(result)

client.query(
  Paginate(
    Match(Index("spells_by_element"), "fire"),
    events = true))

client.query(
  q.paginate(
    q.match(q.index("spells_by_element"), "fire"),
    events=True
  ))

$client.query do
  paginate match(index('spells_by_element'), 'fire'),
           events: true
end

client.query(
    Paginate(
        Match(
            index: Index("spells_by_element"),
            terms: "fire"
        ),
        events: true
    )
)

client.query(
  q.Paginate(
    q.Events(q.Match(q.Index("spells_by_element"), "fire"))))
.then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{
  "resource": {
    "data": [
      {
        "ts": 1509244539203043,
        "action": "create",
        "resource": { "@ref": "classes/spells/181388642046968320" }
      },
      {
        "ts": 1509244539223511,
        "action": "create",
        "resource": { "@ref": "classes/spells/181388642071085568" }
      }
    ]
  }
}

=> {
  "data": [
    {
      "ts": 1509244539203043,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" }
    },
    {
      "ts": 1509244539223511,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" }
    }
  ]
}

=> {
  data: [
    {
      ts: 1527008249876598, 
      action: "add", 
      instance: ref(id = "181388642071085568", class = ref(id = "spells", class = ref(id = "classes")))
    }, 
    {
      ts: 1527008249889400, 
      action: "add", 
      instance: ref(id = "181388642046968320", class = ref(id = "spells", class = ref(id = "classes")))
    }
  ]
}

=> map[data:[
  map[ts:1509244539203043 action:add instance:{181388642046968320 0xc420293a00 <nil>}]
  map[ts:1509244539223511 action:add instance:{181388642071085568 0xc420293cc0 <nil>}]
]]

=> {
  "data": [
    {
      "ts": 1509244539203043,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" }
    },
    {
      "ts": 1509244539223511,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1509244539203043,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" }
    },
    {
      "ts": 1509244539223511,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1509244539203043,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" }
    },
    {
      "ts": 1509244539223511,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1509244539203043,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" }
    },
    {
      "ts": 1509244539223511,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" }
    }
  ]
}

=> { data:
   [ { ts: 1526677776479051,
       action: 'add',
       instance:
        Ref(id=181388642046968320, class=Ref(id=spells, class=Ref(id=classes))) },
     { ts: 1526677776479051,
       action: 'add',
       instance:
        Ref(id=181388642071085568, class=Ref(id=spells, class=Ref(id=classes))) } ] }

union(set_1, set_2, ...)

union represents the set of resources that are present in at least one of the specified sets.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{
          "paginate": {
            "union": [
              {
                "match": { "index": "spells_by_element" },
                "terms": "fire"
              },
              {
                "match": { "index": "spells_by_element" },
                "terms": "water"
              }
            ]
          }
        }'

client.Query(
  Paginate(
    Union(
      Match(Index("spells_by_element"), "fire"),
      Match(Index("spells_by_element"), "water"))));

System.out.println(
      client.query(
        Paginate(
          Union(
            Match(Index(Value("spells_by_element")), Value("fire")),
            Match(Index(Value("spells_by_element")), Value("water"))))
      ).get());

result, _ := client.Query(
    f.Paginate(
        f.Union(
            f.MatchTerm(f.Index("spells_by_element"), "fire"),
            f.MatchTerm(f.Index("spells_by_element"), "water"),
        ),
    ),
)

fmt.Println(result)

client.query(
  Paginate(
    Union(
      Match(Index("spells_by_element"), "fire"),
      Match(Index("spells_by_element"), "water"))))

client.query(
  q.paginate(
    q.union(
      q.match(q.index("spells_by_element"), "fire"),
      q.match(q.index("spells_by_element"), "water")
    )
  ))

$client.query do
  paginate union(match(index('spells_by_element'), 'fire'),
                 match(index('spells_by_element'), 'water'))
end

client.query(
    Paginate(
        Union(
            Match(
                index: Index("spells_by_element"),
                terms: "fire"
            ),
            Match(
                index: Index("spells_by_element"),
                terms: "water"
            )
        )
    )
)

client.query(
  q.Paginate(
    q.Union(
      q.Match(q.Index("spells_by_element"), "fire"),
      q.Match(q.Index("spells_by_element"), "water"))))
.then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{
  "resource": {
    "data": [
      { "@ref": "classes/spells/181388642046968320" },
      { "@ref": "classes/spells/181388642071085568" },
      { "@ref": "classes/spells/181388642088911360" }
    ]
  }
}

=> {
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/spells/181388642071085568" },
    { "@ref": "classes/spells/181388642088911360" }
  ]
}

=> {
  data: [
    ref(id = "181388642046968320", class = ref(id = "spells", class = ref(id = "classes"))),
    ref(id = "181388642071085568", class = ref(id = "spells", class = ref(id = "classes"))),
    ref(id = "181388642088911360", class = ref(id = "spells", class = ref(id = "classes")))
  ]
}

=> map[data:[{181388642046968320 0xc42028d3c0 <nil>} {181388642071085568 0xc42028d5e0 <nil>} {181388642088911360 0xc42028d820 <nil>}]]

=> {
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/spells/181388642071085568" },
    { "@ref": "classes/spells/181388642088911360" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/spells/181388642071085568" },
    { "@ref": "classes/spells/181388642088911360" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/spells/181388642071085568" },
    { "@ref": "classes/spells/181388642088911360" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/spells/181388642071085568" },
    { "@ref": "classes/spells/181388642088911360" }
  ]
}

=> { data:
   [ Ref(id=181388642046968320, class=Ref(id=spells, class=Ref(id=classes))),
     Ref(id=181388642071085568, class=Ref(id=spells, class=Ref(id=classes))),
     Ref(id=181388642088911360, class=Ref(id=spells, class=Ref(id=classes))) ] }

The events view of union contains a unified view of the source sets.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{
          "paginate": {
            "union": [
              {
                "match": { "index": "spells_by_element" },
                "terms": "fire"
              },
              {
                "match": { "index": "spells_by_element" },
                "terms": "water"
              }
            ]
          },
          "events": true
        }'

client.Query(
  Paginate(
    Union(
      Match(Index("spells_by_element"), "fire"),
      Match(Index("spells_by_element"), "water")),
    events: true));

System.out.println(
        client.query(
          Paginate(
            Events(
              Union(
                Match(Index(Value("spells_by_element")), Value("fire")),
                Match(Index(Value("spells_by_element")), Value("water"))
              )
            )
          )
        ).get());

result, _ := client.Query(
    f.Paginate(
        f.Events(
            f.Union(
                f.MatchTerm(f.Index("spells_by_element"), "fire"),
                f.MatchTerm(f.Index("spells_by_element"), "water"),
            ),
        ),
    ),
)

fmt.Println(result)

client.query(
  Paginate(
    Union(
      Match(Index("spells_by_element"), "fire"),
      Match(Index("spells_by_element"), "water")),
    events = true))

client.query(
  q.paginate(
    q.union(
      q.match(q.index("spells_by_element"), "fire"),
      q.match(q.index("spells_by_element"), "water")
    ),
    events=True
  ))

$client.query do
  paginate union(match(index('spells_by_element'), 'fire'),
                 match(index('spells_by_element'), 'water')),
           events: true
end

client.query(
    Paginate(
        Union(
            Match(
                index: Index("spells_by_element"),
                terms: "fire"
            ),
            Match(
                index: Index("spells_by_element"),
                terms: "water"
            )
        ),
        events: true
    )
)

client.query(
  q.Paginate(
    q.Events(q.Union(
      q.Match(q.Index("spells_by_element"), "fire"),
      q.Match(q.Index("spells_by_element"), "water")))))
.then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{
  "resource": {
    "data": [
      {
        "ts": 1509244539203043,
        "action": "create",
        "resource": { "@ref": "classes/spells/181388642046968320" }
      },
      {
        "ts": 1509244539223511,
        "action": "create",
        "resource": { "@ref": "classes/spells/181388642071085568" }
      },
      {
        "ts": 1509244539235128,
        "action": "create",
        "resource": { "@ref": "classes/spells/181388642088911360" }
      }
    ]
  }
}

=> {
  "data": [
    {
      "ts": 1509244539203043,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" }
    },
    {
      "ts": 1509244539223511,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" }
    },
    {
      "ts": 1509244539235128,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642088911360" }
    }
  ]
}

=> {
  data: [
    {
      ts: 1536673654653856, 
      action: "add", 
      instance: ref(id = "181388642071085568", class = ref(id = "spells", class = ref(id = "classes")))
    },
    {
      ts: 1536673654738429, 
      action: "add", 
      instance: ref(id = "181388642046968320", class = ref(id = "spells", class = ref(id = "classes")))
    },
    {
      ts: 1536673654755090, 
      action: "add", 
      instance: ref(id = "181388642088911360", class = ref(id = "spells", class = ref(id = "classes")))
    }
  ]
}

=> map[data:[
  map[ts:1509244539203043 action:add instance:{181388642046968320 0xc4202daf40 <nil>}]
  map[ts:1509244539223511 action:add instance:{181388642071085568 0xc4202db200 <nil>}]
  map[ts:1509244539235128 action:add instance:{181388642088911360 0xc4202db4e0 <nil>}]
]]

=> {
  "data": [
    {
      "ts": 1509244539203043,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" }
    },
    {
      "ts": 1509244539223511,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" }
    },
    {
      "ts": 1509244539235128,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642088911360" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1509244539203043,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" }
    },
    {
      "ts": 1509244539223511,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" }
    },
    {
      "ts": 1509244539235128,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642088911360" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1509244539203043,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" }
    },
    {
      "ts": 1509244539223511,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" }
    },
    {
      "ts": 1509244539235128,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642088911360" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1509244539203043,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" }
    },
    {
      "ts": 1509244539223511,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" }
    },
    {
      "ts": 1509244539235128,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642088911360" }
    }
  ]
}

=> { data:
   [ { ts: 1526677776479051,
       action: 'add',
       instance:
        Ref(id=181388642046968320, class=Ref(id=spells, class=Ref(id=classes))) },
     { ts: 1526677776479051,
       action: 'add',
       instance:
        Ref(id=181388642071085568, class=Ref(id=spells, class=Ref(id=classes))) },
     { ts: 1527095201753208,
       action: 'add',
       instance:
        Ref(id=181388642088911360, class=Ref(id=spells, class=Ref(id=classes))) } ] }

intersection(set_1, set_2, ...)

intersection represents the set of resources that are present in all of the specified sets.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{
          "paginate": {
            "intersection": [
              {
                "match": { "index": "spells_by_element" },
                "terms": "fire"
              },
              {
                "match": { "index": "spells_by_element" },
                "terms": "water"
              }
            ]
          }
        }'

client.Query(
  Paginate(
    Intersection(
      Match(Index("spells_by_element"), "fire"),
      Match(Index("spells_by_element"), "water"))));

System.out.println(
   client.query(
     Paginate(
       Intersection(
         Match(Index(Value("spells_by_element")), Value("fire")),
         Match(Index(Value("spells_by_element")), Value("water"))
       )
     )
   ).get());

result, _ := client.Query(
    f.Paginate(
        f.Intersection(
            f.MatchTerm(f.Index("spells_by_element"), "fire"),
            f.MatchTerm(f.Index("spells_by_element"), "water"),
        ),
    ),
)

fmt.Println(result)

client.query(
  Paginate(
    Intersection(
      Match(Index("spells_by_element"), "fire"),
      Match(Index("spells_by_element"), "water"))))

client.query(
  q.paginate(
    q.intersection(
      q.match(q.index("spells_by_element"), "fire"),
      q.match(q.index("spells_by_element"), "water")
    )
  ))

$client.query do
  paginate intersection(match(index('spells_by_element'), 'fire'),
                        match(index('spells_by_element'), 'water'))
end

client.query(
    Paginate(
        Intersection(
            Match(
                index: Index("spells_by_element"),
                terms: "fire"
            ),
            Match(
                index: Index("spells_by_element"),
                terms: "water"
            )
        )
    )
)

client.query(
  q.Paginate(
    q.Intersection(
      q.Match(q.Index("spells_by_element"), "fire"),
      q.Match(q.Index("spells_by_element"), "water"))))
.then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{
  "resource": {
    "data": [ { "@ref": "classes/spells/181388642071085568" } ]
  }
}

=> { "data": [ { "@ref": "classes/spells/181388642071085568" } ] }

=> {
  data: [
    ref(id = "181388642071085568", class = ref(id = "spells", class = ref(id = "classes")))
  ]
}

=> map[data:[{181388642071085568 0xc4202920a0 <nil>}]]

=> { "data": [ { "@ref": "classes/spells/181388642071085568" } ] }

=> { "data": [ { "@ref": "classes/spells/181388642071085568" } ] }

=> { "data": [ { "@ref": "classes/spells/181388642071085568" } ] }

=> { "data": [ { "@ref": "classes/spells/181388642071085568" } ] }

=> { data: [ Ref(id=181388642071085568, class=Ref(id=spells, class=Ref(id=classes))) ] }

difference(source, set_1, set_2, ...)

difference represents the set of resources present in the source set and not in any of the other specified sets.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{
          "paginate": {
            "difference": [
              {
                "match": { "index": "spells_by_element" },
                "terms": "fire"
              },
              {
                "match": { "index": "spells_by_element" },
                "terms": "water"
              }
            ]
          }
        }'

client.Query(
  Paginate(
    Difference(
      Match(Index("spells_by_element"), "fire"),
      Match(Index("spells_by_element"), "water"))));

System.out.println(
    client.query(
      Paginate(
        Difference(
          Match(Index(Value("spells_by_element")), Value("fire")),
          Match(Index(Value("spells_by_element")), Value("water"))))
    ).get());

result, _ := client.Query(
    f.Paginate(
        f.Difference(
            f.MatchTerm(f.Index("spells_by_element"), "fire"),
            f.MatchTerm(f.Index("spells_by_element"), "water"),
        ),
    ),
)

fmt.Println(result)

client.query(
  Paginate(
    Difference(
      Match(Index("spells_by_element"), "fire"),
      Match(Index("spells_by_element"), "water"))))

client.query(
  q.paginate(
    q.difference(
      q.match(q.index("spells_by_element"), "fire"),
      q.match(q.index("spells_by_element"), "water")
    )
  ))

$client.query do
  paginate difference(match(index('spells_by_element'), 'fire'),
                      match(index('spells_by_element'), 'water'))
end

client.query(
    Paginate(
        Difference(
            Match(
                index: Index("spells_by_element"),
                terms: "fire"
            ),
            Match(
                index: Index("spells_by_element"),
                terms: "water"
            )
        )
    )
)

client.query(
  q.Paginate(
    q.Difference(
      q.Match(q.Index("spells_by_element"), "fire"),
      q.Match(q.Index("spells_by_element"), "water"))))
.then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{
  "resource": {
    "data": [ { "@ref": "classes/spells/181388642046968320" } ]
  }
}

=> { "data": [ { "@ref": "classes/spells/181388642046968320" } ] }

=> {
  data: [
    ref(id = "181388642046968320", class = ref(id = "spells", class = ref(id = "classes")))
  ]
}

=> map[data:[{181388642046968320 0xc420239980 <nil>}]]

=> { "data": [ { "@ref": "classes/spells/181388642046968320" } ] }

=> { "data": [ { "@ref": "classes/spells/181388642046968320" } ] }

=> { "data": [ { "@ref": "classes/spells/181388642046968320" } ] }

=> { "data": [ { "@ref": "classes/spells/181388642046968320" } ] }

=> { data:
   [ Ref(id=181388642046968320, class=Ref(id=spells, class=Ref(id=classes))) ] }

The events view of difference contains events for resources as they enter and exit the logical set over time.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{
          "paginate": {
            "difference": [
              {
                "match": { "index": "spells_by_element" },
                "terms": "fire"
              },
              {
                "match": { "index": "spells_by_element" },
                "terms": "water"
              }
            ]
          },
          "events": true
        }'

client.Query(
  Paginate(
    Difference(
      Match(Index("spells_by_element"), "fire"),
      Match(Index("spells_by_element"), "water")),
    events: true));

System.out.println(
        client.query(
           Paginate(
             Events(
               Difference(
                 Match(Index(Value("spells_by_element")), Value("fire")),
                 Match(Index(Value("spells_by_element")), Value("water"))
               )
             )
           )
        ).get());

result, _ := client.Query(
    f.Paginate(
        f.Events(
            f.Difference(
                f.MatchTerm(f.Index("spells_by_element"), "fire"),
                f.MatchTerm(f.Index("spells_by_element"), "water"),
            ),
        ),
    ),
)

fmt.Println(result)

client.query(
  Paginate(
    Difference(
      Match(Index("spells_by_element"), "fire"),
      Match(Index("spells_by_element"), "water")),
    events = true))

client.query(
  q.paginate(
    q.difference(
      q.match(q.index("spells_by_element"), "fire"),
      q.match(q.index("spells_by_element"), "water")
    ),
    events=True
  ))

$client.query do
  paginate difference(match(index('spells_by_element'), 'fire'),
                      match(index('spells_by_element'), 'water')),
           events: true
end

client.query(
    Paginate(
        Difference(
            Match(
                index: Index("spells_by_element"),
                terms: "fire"
            ),
            Match(
                index: Index("spells_by_element"),
                terms: "water"
            )
        ),
        events: true
    )
)

client.query(
  q.Paginate(
    q.Events(q.Difference(
      q.Match(q.Index("spells_by_element"), "fire"),
      q.Match(q.Index("spells_by_element"), "water")))))
.then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{
  "resource": {
    "data": [
      {
        "ts": 1509244539203043,
        "action": "create",
        "resource": { "@ref": "classes/spells/181388642046968320" }
      },
      {
        "ts": 1509244539223511,
        "action": "create",
        "resource": { "@ref": "classes/spells/181388642071085568" }
      }
    ]
  }
}

=> {
  "data": [
    {
      "ts": 1509244539203043,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" }
    },
    {
      "ts": 1509244539223511,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" }
    }
  ]
}

=> {
  data: [
    {
      ts: 1527002946726063, 
      action: "add", 
      instance: ref(id = "181388642071085568", class = ref(id = "spells", class = ref(id = "classes")))
    },
    {
      ts: 1527002946795516, 
      action: "add", 
      instance: ref(id = "181388642046968320", class = ref(id = "spells", class = ref(id = "classes")))
    }
  ]
}

=> map[data:[
  map[ts:1509244539203043 action:add instance:{181388642046968320 0xc420261160 <nil>}]
  map[ts:1509244539223511 action:add instance:{181388642071085568 0xc420261420 <nil>}]
]]

=> {
  "data": [
    {
      "ts": 1509244539203043,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" }
    },
    {
      "ts": 1509244539223511,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1509244539203043,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" }
    },
    {
      "ts": 1509244539223511,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1509244539203043,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" }
    },
    {
      "ts": 1509244539223511,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1509244539203043,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" }
    },
    {
      "ts": 1509244539223511,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" }
    }
  ]
}

=> { data:
   [ { ts: 1526677776479051,
       action: 'add',
       instance:
        Ref(id=181388642046968320, class=Ref(id=spells, class=Ref(id=classes))) },
     { ts: 1526677776479051,
       action: 'add',
       instance:
        Ref(id=181388642071085568, class=Ref(id=spells, class=Ref(id=classes))) } ] }

distinct(set)

Sometimes, sets can contain the same values coming in from different resources. The distinct function returns the set after removing duplicates.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "paginate": { "match": { "index": "elements_of_spells" } } }'

client.Query(Paginate(Match(Index("elements_of_spells"))));

System.out.println(
    client.query(
      Paginate(Match(Index(Value("elements_of_spells"))))
    ).get());

result, _ := client.Query(f.Paginate(f.Match(f.Index("elements_of_spells"))))

fmt.Println(result)

client.query(Paginate(Match(Index("elements_of_spells"))))

client.query(q.paginate(q.match(q.index("elements_of_spells"))))

$client.query do
  paginate match(index('elements_of_spells'))
end

client.query(
    Paginate(Match(index: Index("elements_of_spells")))
)

client.query(q.Paginate(q.Match(q.Index("elements_of_spells"))))
  .then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{
  "resource": {
    "data": [ "air", "earth", "fire", "fire", "water", "water" ]
  }
}

=> {
  "data": [ "air", "earth", "fire", "fire", "water", "water" ]
}

=> {
  data: ["air", "earth", "fire", "fire", "water", "water"]
}

=> map[data:[air earth fire fire water water]]

=> {
  "data": [ "air", "earth", "fire", "fire", "water", "water" ]
}

=> {
  "data": [ "air", "earth", "fire", "fire", "water", "water" ]
}

=> {
  "data": [ "air", "earth", "fire", "fire", "water", "water" ]
}

=> {
  "data": [ "air", "earth", "fire", "fire", "water", "water" ]
}

=> { data: [ 'air', 'earth', 'fire', 'fire', 'water', 'water' ] }

From the “flattened” list of elements from the query above, we can see that 'fire' and 'water' are duplicated.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{
          "paginate": {
            "distinct": { "match": { "index": "elements_of_spells" } }
          }
        }'

client.Query(
  Paginate(Distinct(Match(Index("elements_of_spells")))));

System.out.println(
        client.query(
           Paginate(Distinct(Match(Index(Value("elements_of_spells")))))
        ).get());

result, _ := client.Query(
    f.Paginate(
        f.Distinct(f.Match(f.Index("elements_of_spells"))),
    ),
)

fmt.Println(result)

client.query(
  Paginate(Distinct(Match(Index("elements_of_spells")))))

client.query(
  q.paginate(q.distinct(q.match(q.index("elements_of_spells")))))

$client.query do
  paginate distinct(match(index('elements_of_spells')))
end

client.query(
    Paginate(
        Distinct(Match(index: Index("elements_of_spells")))
    )
)

client.query(q.Paginate(q.Distinct(q.Match(q.Index("elements_of_spells")))))
  .then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{ "resource": { "data": [ "air", "earth", "fire", "water" ] } }

=> { "data": [ "air", "earth", "fire", "water" ] }

=> { data: ["air", "earth", "fire", "water"] }

=> map[data:[air earth fire water]]

=> { "data": [ "air", "earth", "fire", "water" ] }

=> { "data": [ "air", "earth", "fire", "water" ] }

=> { "data": [ "air", "earth", "fire", "water" ] }

=> { "data": [ "air", "earth", "fire", "water" ] }

=> { data: [ 'air', 'earth', 'fire', 'water' ] }

As the events view of a set of values include the resources themselves, the distinct function returns the same set.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{
          "paginate": {
            "distinct": { "match": { "index": "elements_of_spells" } }
          },
          "events": true
        }'

client.Query(
  Paginate(
    Distinct(Match(Index("elements_of_spells"))),
    events: true));

System.out.println(
     client.query(
        Events(
          Paginate(Distinct(Match(Index(Value("elements_of_spells")))))
        )
     ).get());

result, _ := client.Query(
    f.Paginate(
        f.Events(
            f.Distinct(f.Match(f.Index("elements_of_spells"))),
        ),
    ),
)

fmt.Println(result)

client.query(
  Paginate(
    Distinct(Match(Index("elements_of_spells"))),
    events = true))

client.query(
  q.paginate(
    q.distinct(q.match(q.index("elements_of_spells"))),
    events=True
  ))

$client.query do
  paginate distinct(match(index('elements_of_spells'))),
           events: true
end

client.query(
    Paginate(
        Distinct(Match(index: Index("elements_of_spells"))),
        events: true
    )
)

client.query(
  q.Paginate(
    q.Events(q.Distinct(q.Match(q.Index("elements_of_spells"))))))
.then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{
  "resource": {
    "data": [
      {
        "ts": 1509244539203043,
        "action": "create",
        "resource": { "@ref": "classes/spells/181388642046968320" },
        "values": [ "air" ]
      },
      {
        "ts": 1509244539203043,
        "action": "create",
        "resource": { "@ref": "classes/spells/181388642046968320" },
        "values": [ "fire" ]
      },
      {
        "ts": 1509244539223511,
        "action": "create",
        "resource": { "@ref": "classes/spells/181388642071085568" },
        "values": [ "fire" ]
      },
      {
        "ts": 1509244539223511,
        "action": "create",
        "resource": { "@ref": "classes/spells/181388642071085568" },
        "values": [ "water" ]
      },
      {
        "ts": 1509244539235128,
        "action": "create",
        "resource": { "@ref": "classes/spells/181388642088911360" },
        "values": [ "earth" ]
      },
      {
        "ts": 1509244539235128,
        "action": "create",
        "resource": { "@ref": "classes/spells/181388642088911360" },
        "values": [ "water" ]
      },
      {
        "ts": 1509244539709690,
        "action": "create",
        "resource": { "@ref": "classes/spells/181388642581742080" },
        "values": [ "air" ]
      },
      {
        "ts": 1509244539764856,
        "action": "create",
        "resource": { "@ref": "classes/spells/181388642581742080" },
        "values": [ "earth" ]
      },
      {
        "ts": 1509244539795464,
        "action": "delete",
        "resource": { "@ref": "classes/spells/181388642581742080" },
        "values": [ "air" ]
      },
      {
        "ts": 1509244539795464,
        "action": "delete",
        "resource": { "@ref": "classes/spells/181388642581742080" },
        "values": [ "earth" ]
      }
    ]
  }
}

=> {
  "data": [
    {
      "ts": 1509244539203043,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" },
      "values": [ "air" ]
    },
    {
      "ts": 1509244539203043,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" },
      "values": [ "fire" ]
    },
    {
      "ts": 1509244539223511,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" },
      "values": [ "fire" ]
    },
    {
      "ts": 1509244539223511,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" },
      "values": [ "water" ]
    },
    {
      "ts": 1509244539235128,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642088911360" },
      "values": [ "earth" ]
    },
    {
      "ts": 1509244539235128,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642088911360" },
      "values": [ "water" ]
    },
    {
      "ts": 1509244539709690,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642581742080" },
      "values": [ "air" ]
    },
    {
      "ts": 1509244539764856,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642581742080" },
      "values": [ "earth" ]
    },
    {
      "ts": 1509244539795464,
      "action": "delete",
      "resource": { "@ref": "classes/spells/181388642581742080" },
      "values": [ "air" ]
    },
    {
      "ts": 1509244539795464,
      "action": "delete",
      "resource": { "@ref": "classes/spells/181388642581742080" },
      "values": [ "earth" ]
    }
  ]
}

=> {
  data: [
    {
      ts: 1527267261636139, 
      action: "add", 
      instance: ref(id = "181388642071085568", class = ref(id = "spells", class = ref(id = "classes"))), 
      data: ["fire"]
    {
      ts: 1527267261636139, 
      action: "add", 
      instance: ref(id = "181388642071085568", class = ref(id = "spells", class = ref(id = "classes"))), 
      data: ["water"]
    {
      ts: 1527267261664785, 
      action: "add", 
      instance: ref(id = "181388642046968320", class = ref(id = "spells", class = ref(id = "classes"))), 
      data: ["air"]
    {
      ts: 1527267261664785, 
      action: "add", 
      instance: ref(id = "181388642046968320", class = ref(id = "spells", class = ref(id = "classes"))), 
      data: ["fire"]
    {
      ts: 1527267261713947, 
      action: "add", 
      instance: ref(id = "181388642088911360", class = ref(id = "spells", class = ref(id = "classes"))), 
      data: ["earth"]
    {
      ts: 1527267261713947, 
      action: "add", 
      instance: ref(id = "181388642088911360", class = ref(id = "spells", class = ref(id = "classes"))), 
      data: ["water"]
    {
      ts: 1527267261924953, 
      action: "add", 
      instance: ref(id = "181388642581742080", class = ref(id = "spells", class = ref(id = "classes"))), 
      data: ["air"]
    {
      ts: 1527267261964739, 
      action: "remove", 
      instance: ref(id = "181388642581742080", class = ref(id = "spells", class = ref(id = "classes"))), 
      data: ["air"]
    {
      ts: 1527267262013935, 
      action: "add", 
      instance: ref(id = "181388642581742080", class = ref(id = "spells", class = ref(id = "classes"))), 
      data: ["air"]
    {
      ts: 1527267262062984, 
      action: "remove", 
      instance: ref(id = "181388642581742080", class = ref(id = "spells", class = ref(id = "classes"))), 
      data: ["air"]
    }
  ]
}

=> map[data:[
  map[ts:1509244539203043 action:add instance:{181388642046968320 0xc42026c920 <nil>} data:[air]]
  map[ts:1509244539203043 action:add instance:{181388642046968320 0xc42026cc40 <nil>} data:[fire]]
  map[ts:1509244539223511 action:add instance:{181388642071085568 0xc42026cf80 <nil>} data:[fire]]
  map[ts:1509244539223511 action:add instance:{181388642071085568 0xc42026d2a0 <nil>} data:[water]]
  map[ts:1509244539235128 action:add instance:{181388642088911360 0xc42026d5c0 <nil>} data:[earth]]
  map[ts:1509244539235128 action:add instance:{181388642088911360 0xc42026d8e0 <nil>} data:[water]]
  map[ts:1509244539709690 action:add instance:{181388642581742080 0xc42026dc00 <nil>} data:[air]]
  map[ts:1509244539764856 action:add instance:{181388642581742080 0xc42026df20 <nil>} data:[earth]]
  map[ts:1509244539795464 action:remove instance:{181388642581742080 0xc420284240 <nil>} data:[air]]
  map[ts:1509244539795464 action:remove instance:{181388642581742080 0xc420284560 <nil>} data:[earth]]
]]

=> {
  "data": [
    {
      "ts": 1509244539203043,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" },
      "values": [ "air" ]
    },
    {
      "ts": 1509244539203043,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" },
      "values": [ "fire" ]
    },
    {
      "ts": 1509244539223511,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" },
      "values": [ "fire" ]
    },
    {
      "ts": 1509244539223511,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" },
      "values": [ "water" ]
    },
    {
      "ts": 1509244539235128,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642088911360" },
      "values": [ "earth" ]
    },
    {
      "ts": 1509244539235128,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642088911360" },
      "values": [ "water" ]
    },
    {
      "ts": 1509244539709690,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642581742080" },
      "values": [ "air" ]
    },
    {
      "ts": 1509244539764856,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642581742080" },
      "values": [ "earth" ]
    },
    {
      "ts": 1509244539795464,
      "action": "delete",
      "resource": { "@ref": "classes/spells/181388642581742080" },
      "values": [ "air" ]
    },
    {
      "ts": 1509244539795464,
      "action": "delete",
      "resource": { "@ref": "classes/spells/181388642581742080" },
      "values": [ "earth" ]
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1509244539203043,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" },
      "values": [ "air" ]
    },
    {
      "ts": 1509244539203043,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" },
      "values": [ "fire" ]
    },
    {
      "ts": 1509244539223511,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" },
      "values": [ "fire" ]
    },
    {
      "ts": 1509244539223511,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" },
      "values": [ "water" ]
    },
    {
      "ts": 1509244539235128,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642088911360" },
      "values": [ "earth" ]
    },
    {
      "ts": 1509244539235128,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642088911360" },
      "values": [ "water" ]
    },
    {
      "ts": 1509244539709690,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642581742080" },
      "values": [ "air" ]
    },
    {
      "ts": 1509244539764856,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642581742080" },
      "values": [ "earth" ]
    },
    {
      "ts": 1509244539795464,
      "action": "delete",
      "resource": { "@ref": "classes/spells/181388642581742080" },
      "values": [ "air" ]
    },
    {
      "ts": 1509244539795464,
      "action": "delete",
      "resource": { "@ref": "classes/spells/181388642581742080" },
      "values": [ "earth" ]
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1509244539203043,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" },
      "values": [ "air" ]
    },
    {
      "ts": 1509244539203043,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" },
      "values": [ "fire" ]
    },
    {
      "ts": 1509244539223511,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" },
      "values": [ "fire" ]
    },
    {
      "ts": 1509244539223511,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" },
      "values": [ "water" ]
    },
    {
      "ts": 1509244539235128,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642088911360" },
      "values": [ "earth" ]
    },
    {
      "ts": 1509244539235128,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642088911360" },
      "values": [ "water" ]
    },
    {
      "ts": 1509244539709690,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642581742080" },
      "values": [ "air" ]
    },
    {
      "ts": 1509244539764856,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642581742080" },
      "values": [ "earth" ]
    },
    {
      "ts": 1509244539795464,
      "action": "delete",
      "resource": { "@ref": "classes/spells/181388642581742080" },
      "values": [ "air" ]
    },
    {
      "ts": 1509244539795464,
      "action": "delete",
      "resource": { "@ref": "classes/spells/181388642581742080" },
      "values": [ "earth" ]
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1509244539203043,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" },
      "values": [ "air" ]
    },
    {
      "ts": 1509244539203043,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" },
      "values": [ "fire" ]
    },
    {
      "ts": 1509244539223511,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" },
      "values": [ "fire" ]
    },
    {
      "ts": 1509244539223511,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" },
      "values": [ "water" ]
    },
    {
      "ts": 1509244539235128,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642088911360" },
      "values": [ "earth" ]
    },
    {
      "ts": 1509244539235128,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642088911360" },
      "values": [ "water" ]
    },
    {
      "ts": 1509244539709690,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642581742080" },
      "values": [ "air" ]
    },
    {
      "ts": 1509244539764856,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642581742080" },
      "values": [ "earth" ]
    },
    {
      "ts": 1509244539795464,
      "action": "delete",
      "resource": { "@ref": "classes/spells/181388642581742080" },
      "values": [ "air" ]
    },
    {
      "ts": 1509244539795464,
      "action": "delete",
      "resource": { "@ref": "classes/spells/181388642581742080" },
      "values": [ "earth" ]
    }
  ]
}

=> { data:
  [  { ts: 1527095186458101,
       action: 'add',
       instance:
        Ref(id=181388642046968320, class=Ref(id=spells, class=Ref(id=classes))),
       data: [Array] },
     { ts: 1527095186458101,
       action: 'add',
       instance:
        Ref(id=181388642046968320, class=Ref(id=spells, class=Ref(id=classes))),
       data: [Array] },
     { ts: 1527095186458101,
       action: 'add',
       instance:
        Ref(id=181388642071085568, class=Ref(id=spells, class=Ref(id=classes))),
       data: [Array] },
     { ts: 1527095186458101,
       action: 'add',
       instance:
        Ref(id=181388642071085568, class=Ref(id=spells, class=Ref(id=classes))),
       data: [Array] },
     { ts: 1527095186458101,
       action: 'add',
       instance:
        Ref(id=181388642088911360, class=Ref(id=spells, class=Ref(id=classes))),
       data: [Array] },
     { ts: 1527095186458101,
       action: 'add',
       instance:
        Ref(id=181388642088911360, class=Ref(id=spells, class=Ref(id=classes))),
       data: [Array] },
     { ts: 1527095186458101,
       action: 'add',
       instance:
        Ref(id=181388642581742080, class=Ref(id=spells, class=Ref(id=classes))),
       data: [Array] },
     { ts: 1527095186458101,
       action: 'add',
       instance:
        Ref(id=181388642581742080, class=Ref(id=spells, class=Ref(id=classes))),
       data: [Array] },
     { ts: 1527095186458101,
       action: 'remove',
       instance:
        Ref(id=181388642581742080, class=Ref(id=spells, class=Ref(id=classes))),
       data: [Array] },
     { ts: 1527095186458101,
       action: 'remove',
       instance:
        Ref(id=181388642581742080, class=Ref(id=spells, class=Ref(id=classes))),
       data: [Array] } ] }

join(source_set, with)

join derives a set of resources from with by applying each instance in source_set to with

with can be either an index reference or a lambda function

The index form is useful when the instances in the source_set match the terms in an index. The join returns instances from index (specified by with) that match the terms from source_set


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{
          "paginate": {
            "join": {
              "match": { "index": "spellbooks_by_owner" },
              "terms": { "@ref": "classes/characters/181388642114077184" }
            },
            "with": { "index": "spells_by_spellbook" }
          }
        }'

client.Query(
  Paginate(
    Join(
      Match(
        Index("spellbooks_by_owner"),
        Ref("classes/characters/181388642114077184")),
      Index("spells_by_spellbook"))));

client.query(
  Paginate(
      Join(
        Match(
          Index(Value("spellbooks_by_owner")),
          Ref("classes/characters/181388642114077184")),
        Index(Value("spells_by_spellbook")))));

result, _ := client.Query(
    f.Paginate(
        f.Join(
            f.MatchTerm(
                f.Index("spellbooks_by_owner"),
                f.RefClass(f.Class("characters"), "181388642114077184"),
            ),
            f.Index("spells_by_spellbook"),
        ),
    ),
)

fmt.Println(result)

client.query(
  Paginate(
    Join(
      Match(
        Index("spellbooks_by_owner"),
        Ref("classes/characters/181388642114077184")),
      Index("spells_by_spellbook"))))

client.query(
  q.paginate(
    q.join(
      q.match(
        q.index("spellbooks_by_owner"),
        Ref("classes/characters/181388642114077184")
      ),
      q.index("spells_by_spellbook")
    )
  ))

$client.query do
  paginate join match(index('spellbooks_by_owner'),
                 ref('classes/characters/181388642114077184')) index('spells_by_spellbook')
end

client.query(
    Paginate(
        Join(
            Match(
                index: Index("spellbooks_by_owner"),
                terms: Ref("classes/characters/181388642114077184")
            ),
            with: Index("spells_by_spellbook")
        )
    )
)

client.query(
  q.Paginate(
    q.Join(
      q.Match(
        q.Index("spellbooks_by_owner"),
        q.Ref(q.Class("characters"), "181388642114077184")),
      q.Index("spells_by_spellbook"))))
.then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{
  "resource": {
    "data": [
      { "@ref": "classes/spells/181388642046968320" },
      { "@ref": "classes/spells/181388642071085568" }
    ]
  }
}

=> {
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/spells/181388642071085568" }
  ]
}

=> {
  data: [
    ref(id = "181388642046968320", class = ref(id="spells", class = ref(id = "classes"))),
    ref(id = "181388642071085568", class = ref(id="spells", class = ref(id = "classes")))
  ]
}

=> map[data:[{181388642046968320 0xc4202478a0 <nil>} {181388642071085568 0xc420247ac0 <nil>}]]

=> {
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/spells/181388642071085568" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/spells/181388642071085568" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/spells/181388642071085568" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/spells/181388642071085568" }
  ]
}

=> { data:
   [ Ref(id=181388642046968320, class=Ref(id=spells, class=Ref(id=classes))),
     Ref(id=181388642071085568, class=Ref(id=spells, class=Ref(id=classes))) ] }

The lambda form requires the lambda function to be pure. i.e. it may not make any reads or writes


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{
          "paginate": {
            "join": {
              "match": { "index": "spellbooks_by_owner" },
              "terms": { "@ref": "classes/characters/181388642114077184" }
            },
            "with": {
              "lambda": "spellbook",
              "expr": {
                "match": { "index": "spells_by_spellbook" },
                "terms": { "var": "spellbook" }
              }
            }
          }
        }'

client.Query(
  Paginate(
    Join(
      Match(
        Index("spellbooks_by_owner"),
        Ref("classes/characters/181388642114077184")),
      Lambda(
        "spellbook",
        Match(Index("spells_by_spellbook"), Var("spellbook"))))));

client.query(
  Paginate(
      Join(
        Match(
          Index(Value("spellbooks_by_owner")),
          Ref("classes/characters/181388642114077184")),
        Lambda(
          Value("spellbook"),
          Match(
            Index(Value("spells_by_spellbook")),
            Var("spellbook"))))));

result, _ := client.Query(
    f.Paginate(
        f.Join(
            f.MatchTerm(
                f.Index("spellbooks_by_owner"),
                f.RefClass(f.Class("characters"), "181388642114077184"),
            ),
            f.Lambda(
                "spellbook",
                f.MatchTerm(
                    f.Index("spells_by_spellbook"),
                    f.Var("spellbook"),
                ),
            ),
        ),
    ),
)

fmt.Println(result)

client.query(
  Paginate(
    Join(
      Match(
        Index("spellbooks_by_owner"),
        Ref("classes/characters/181388642114077184")),
      Lambda { spellbook =>
        Match(Index("spells_by_spellbook"), spellbook)
      })))

client.query(
  q.paginate(
    q.join(
      q.match(
        q.index("spellbooks_by_owner"),
        Ref("classes/characters/181388642114077184")
      ),
      q.lambda_expr(
        "spellbook",
        q.match(
          q.index("spells_by_spellbook"),
          q.var("spellbook")
        )
      )
    )
  ))

$client.query do
  paginate join(match(index('spellbooks_by_owner'),
                      ref('classes/characters/181388642114077184')),
                lambda_expr('spellbook',
                            match(index('spells_by_spellbook'), var('spellbook'))))
end

client.query(
    Paginate(
        Join(
            Match(
                index: Index("spellbooks_by_owner"),
                terms: Ref("classes/characters/181388642114077184")
            ),
            with: Lambda(
                vars: "spellbook"
                in: Match(
                    index: Index("spells_by_spellbook"),
                    terms: Var("spellbook")
                )
            )
        )
    )
)

client.query(
  q.Paginate(
    q.Join(
      q.Match(
        q.Index("spellbooks_by_owner"),
        q.Ref(q.Class("characters"), "181388642114077184")),
      q.Lambda("spellbook", q.Match(q.Index("spells_by_spellbook"), q.Var("spellbook"))))))
.then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{
  "resource": {
    "data": [
      { "@ref": "classes/spells/181388642046968320" },
      { "@ref": "classes/spells/181388642071085568" }
    ]
  }
}

=> {
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/spells/181388642071085568" }
  ]
}

=> {
  "data": [
    ref(id = "181388642046968320", class = ref(id="spells", class = ref(id = "classes"))),
    ref(id = "181388642071085568", class = ref(id="spells", class = ref(id = "classes")))
  ]
}

=> map[data:[{181388642046968320 0xc42029a8e0 <nil>} {181388642071085568 0xc42029ab00 <nil>}]]

=> {
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/spells/181388642071085568" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/spells/181388642071085568" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/spells/181388642071085568" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/spells/181388642071085568" }
  ]
}

=> { data:
   [ Ref(id=181388642046968320, class=Ref(id=spells, class=Ref(id=classes))),
     Ref(id=181388642071085568, class=Ref(id=spells, class=Ref(id=classes))) ] }

The events view of join contains events for joined sets as the join filtered by when the join instance was live in the source set.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{
          "paginate": {
            "join": {
              "match": { "index": "spellbooks_by_owner" },
              "terms": { "@ref": "classes/characters/181388642114077184" }
            },
            "with": {
              "lambda": "spellbook",
              "expr": {
                "match": { "index": "spells_by_spellbook" },
                "terms": { "var": "spellbook" }
              }
            }
          },
          "events": true
        }'

client.Query(
  Paginate(
    Join(
      Match(
        Index("spellbooks_by_owner"),
        Ref("classes/characters/181388642114077184")),
      Lambda(
        "spellbook",
        Match(Index("spells_by_spellbook"), Var("spellbook")))),
    events: true));

client.query(
  Paginate(
      Join(
        Match(
          Index(Value("spellbooks_by_owner")),
          Ref("classes/characters/181388642114077184")),
        Lambda(
          Value("spellbook"),
          Match(
            Index(Value("spells_by_spellbook")),
            Var("spellbook")))))
    .events(Value(true)));

result, _ := client.Query(
    f.Paginate(
        f.Events(
            f.Join(
                f.MatchTerm(
                    f.Index("spellbooks_by_owner"),
                    f.RefClass(f.Class("characters"), "181388642114077184"),
                ),
                f.Lambda(
                    "spellbook",
                    f.MatchTerm(
                        f.Index("spells_by_spellbook"),
                        f.Var("spellbook"),
                    ),
                ),
            ),
        ),
    ),
)

fmt.Println(result)

client.query(
  Paginate(
    Join(
      Match(
        Index("spellbooks_by_owner"),
        Ref("classes/characters/181388642114077184")),
      Lambda { spellbook =>
        Match(Index("spells_by_spellbook"), spellbook)
      }),
    events = true))

client.query(
  q.paginate(
    q.join(
      q.match(
        q.index("spellbooks_by_owner"),
        Ref("classes/characters/181388642114077184")
      ),
      q.lambda_expr(
        "spellbook",
        q.match(
          q.index("spells_by_spellbook"),
          q.var("spellbook")
        )
      )
    ),
    events=True
  ))

$client.query do
  paginate join(match(index('spellbooks_by_owner'),
                      ref('classes/characters/181388642114077184')),
                lambda_expr('spellbook',
                            match(index('spells_by_spellbook'), var('spellbook')))),
           events: true
end

client.query(
    Paginate(
        Join(
            Match(
                index: Index("spellbooks_by_owner"),
                terms: Ref("classes/characters/181388642114077184")
            ),
            with: Lambda(
                vars: "spellbook"
                in: Match(
                    index: Index("spells_by_spellbook"),
                    terms: Var("spellbook")
                )
            )
        ),
        events: true
    )
)

client.query(
  q.Paginate(
    q.Events(q.Join(
      q.Match(
        q.Index("spellbooks_by_owner"),
        q.Ref(q.Class("characters"), "181388642114077184")),
      q.Index("spells_by_spellbook")))))
.then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{
  "resource": {
    "data": [
      {
        "ts": 1509244539547758,
        "action": "create",
        "resource": { "@ref": "classes/spells/181388642046968320" }
      },
      {
        "ts": 1509244539547758,
        "action": "create",
        "resource": { "@ref": "classes/spells/181388642071085568" }
      }
    ]
  }
}

=> {
  "data": [
    {
      "ts": 1509244539547758,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" }
    },
    {
      "ts": 1509244539547758,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" }
    }
  ]
}

=> {
  "data": [
    {
      ts: 1509244539547758,
      action: "create",
      resource: ref(id = "181388642046968320", class = ref(id="spells", class = ref(id = "classes")))
    },
    {
      ts: 1509244539547758,
      action: "create",
      resource: ref(id = "181388642071085568", class = ref(id="spells", class = ref(id = "classes")))
    }
  ]
}

=> map[data:[
  map[ts:1509244539547758 action:add instance:{181388642046968320 0xc420285c60 <nil>}]
  map[ts:1509244539547758 action:add instance:{181388642071085568 0xc420285f20 <nil>}]
]]

=> {
  "data": [
    {
      "ts": 1509244539547758,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" }
    },
    {
      "ts": 1509244539547758,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1509244539547758,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" }
    },
    {
      "ts": 1509244539547758,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1509244539547758,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" }
    },
    {
      "ts": 1509244539547758,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1509244539547758,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" }
    },
    {
      "ts": 1509244539547758,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" }
    }
  ]
}

=> { data:
  [  { ts: 1527095186458101,
       action: 'add',
       instance:
        Ref(id=181388642046968320, class=Ref(id=spells, class=Ref(id=classes))) },
     { ts: 1527095186458101,
       action: 'add',
       instance:
        Ref(id=181388642071085568, class=Ref(id=spells, class=Ref(id=classes))) } ] }

Authentication

login(ref, param_object)

login creates a token for the provided ref.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{
          "login": { "@ref": "classes/characters/181388642114077184" },
          "params": { "object": { "password": "abracadabra" } }
        }'

client.Query(
  Login(
    Ref("classes/characters/181388642114077184"),
    Obj("password", "abracadabra")));

System.out.println(
       client.query(
           Login(
             Ref(Class("characters"), Value(181388642114077184L)),
             Obj("password", Value("abracadabra")))
       ).get());

result, _ := client.Query(
    f.Login(
        f.RefClass(f.Class("characters"), "181388642114077184"),
        f.Obj{"password": "abracadabra"},
    ),
)

fmt.Println(result)

client.query(
  Login(
    Ref("classes/characters/181388642114077184"),
    Obj("password" -> "abracadabra")))

client.query(
  q.login(
    Ref("classes/characters/181388642114077184"),
    {"password": "abracadabra"}
  ))

$client.query do
  login ref('classes/characters/181388642114077184'),
        password: 'abracadabra'
end

client.query(
    Login(
        for: Ref("classes/characters/181388642114077184"),
        Obj("password" => "abracadabra")
    )
)

client.query(
  q.Login(q.Ref(q.Class("characters"), "181388642114077184"), { password: "abracadabra" }))
.then((ret) => console.log(ret))

=> HTTP/1.1 201 Created
{
  "resource": {
    "ref": { "@ref": "tokens/181388643175236096" },
    "class": { "@ref": "tokens" },
    "ts": 1509244540264619,
    "instance": { "@ref": "classes/characters/181388642114077184" },
    "secret": "fnEChGwCisACAAKEbAFuUAIAwIxOcffRgoJm7EgUt_zlmiPOze4"
  }
}

=> {
  "ref": { "@ref": "tokens/181388643175236096" },
  "class": { "@ref": "tokens" },
  "ts": 1509244540264619,
  "instance": { "@ref": "classes/characters/181388642114077184" },
  "secret": "fnEChGwCisACAAKEbAFuUAIAwIxOcffRgoJm7EgUt_zlmiPOze4"
}

=> {
  ref: ref(id = "210072853209416192", class = ref(id = "tokens")),
  ts: 1536599934671870,
  instance: ref(id = "181388642114077184", class = ref(id = "characters", class = ref(id = "classes"))),
  secret: "fnEC6lQloIACAALqVCVT8AIAtHiABBu-jZoAKERviRRl5bjZNBQ"
}

=> map[ref:{181388643175236096 0xc4202b3440 <nil>} ts:1509244540264619 instance:{181388642114077184 0xc4202b36c0 <nil>} secret:fnEChGwCisACAAKEbAFuUAIAwIxOcffRgoJm7EgUt_zlmiPOze4]

=> {
  "ref": { "@ref": "tokens/181388643175236096" },
  "class": { "@ref": "tokens" },
  "ts": 1509244540264619,
  "instance": { "@ref": "classes/characters/181388642114077184" },
  "secret": "fnEChGwCisACAAKEbAFuUAIAwIxOcffRgoJm7EgUt_zlmiPOze4"
}

=> {
  "ref": { "@ref": "tokens/181388643175236096" },
  "class": { "@ref": "tokens" },
  "ts": 1509244540264619,
  "instance": { "@ref": "classes/characters/181388642114077184" },
  "secret": "fnEChGwCisACAAKEbAFuUAIAwIxOcffRgoJm7EgUt_zlmiPOze4"
}

=> {
  "ref": { "@ref": "tokens/181388643175236096" },
  "class": { "@ref": "tokens" },
  "ts": 1509244540264619,
  "instance": { "@ref": "classes/characters/181388642114077184" },
  "secret": "fnEChGwCisACAAKEbAFuUAIAwIxOcffRgoJm7EgUt_zlmiPOze4"
}

=> {
  "ref": { "@ref": "tokens/181388643175236096" },
  "class": { "@ref": "tokens" },
  "ts": 1509244540264619,
  "instance": { "@ref": "classes/characters/181388642114077184" },
  "secret": "fnEChGwCisACAAKEbAFuUAIAwIxOcffRgoJm7EgUt_zlmiPOze4"
}

=> { ref: Ref(id=181388643175236096, class=Ref(id=tokens)),
  ts: 1527279532953934,
  instance:
   Ref(id=181388642114077184, class=Ref(id=characters, class=Ref(id=classes))),
  secret: 'fnECx5uE8OACAQLCZP7uQAIBF3rvpXoJEzfIrNXEL21PUpib9AE' }

logout(all_tokens)

logout deletes all tokens associated with the current session if its parameter is true, or just the token used in this request otherwise.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "logout": true }'

client.Query(Logout(true));

System.out.println(client.query(Logout(Value(true))).get());

result, _ := client.Query(f.Logout(true))

fmt.Println(result)

client.query(Logout(true))

client.query(q.logout(True))

$client.query do
  logout true
end

client.query(Logout(all: true))

client.query(q.Logout(true))
  .then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{ "resource": false }

=> false

=> false

=> false

=> false

=> false

=> false

=> false

=> true

identify(ref, password)

identify checks the given password against the ref’s credentials, returning true if the credentials are valid, or false otherwise.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{
          "identify": { "@ref": "classes/characters/181388642114077184" },
          "password": "abracadabra"
        }'

client.Query(
  Identify(
    Ref("classes/characters/181388642114077184"),
    "abracadabra"));

System.out.println(
         client.query(
             Identify(
               Ref(Class("characters"), Value(181388642114077184L)),
               Value("abracadabra")))
         .get());

result, _ := client.Query(
    f.Identify(
        f.RefClass(f.Class("characters"), "181388642114077184"),
        "abracadabra",
    ),
)

fmt.Println(result)

client.query(
  Identify(
    Ref("classes/characters/181388642114077184"),
    "abracadabra"))

client.query(
  q.identify(
    Ref("classes/characters/181388642114077184"),
    "abracadabra"
  ))

$client.query do
  identify ref('classes/characters/181388642114077184'),
           'abracadabra'
end

client.query(
    Identify(
        ref: Ref("classes/characters/181388642114077184"),
        password: "abracadabra"
    )
)

client.query(
  q.Identify(q.Ref(q.Class("characters"), "181388642114077184"), "abracadabra"))
.then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{ "resource": true }

=> true

=> true

=> true

=> true

=> true

=> true

=> true

=> true

identity()

identity will return the ref of the instance associated with the authentication token used for the request. If an instance does not exist, an error will be returned.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "identity": null }'

// Not available in this language yet.

System.out.println(client.query(Get(Identity())).get());

result, _ := client.Query(f.Identity())

fmt.Println(result)

// Not available in this language yet.

# Not available in this language yet.

# Not available in this language yet.

// Not available in this language yet.

client.query(q.Identity())
  .then((ret) => console.log(ret))

=> HTTP/1.1 400 Bad Request
{
  "errors": [
    {
      "position": [  ],
      "code": "missing identity",
      "description": "Authentication does not contain an identity"
    }
  ]
}

=> {
  "errors": [
    {
      "position": [  ],
      "code": "missing identity",
      "description": "Authentication does not contain an identity"
    }
  ]
}

=> {
  ref: (id = "200118070142829056", class = ref(id = "users", class = ref(id = "classes"))),
  ts: 1527106313732119,
  data: {email: "alice@example.com"}
}

=> {181388642114077184 0xc4202d09e0 <nil>}

=> {
  "errors": [
    {
      "position": [  ],
      "code": "missing identity",
      "description": "Authentication does not contain an identity"
    }
  ]
}

=> {
  "errors": [
    {
      "position": [  ],
      "code": "missing identity",
      "description": "Authentication does not contain an identity"
    }
  ]
}

=> {
  "errors": [
    {
      "position": [  ],
      "code": "missing identity",
      "description": "Authentication does not contain an identity"
    }
  ]
}

=> {
  "errors": [
    {
      "position": [  ],
      "code": "missing identity",
      "description": "Authentication does not contain an identity"
    }
  ]
}

=> Ref(id=181388642114077184, class=Ref(id=characters, class=Ref(id=classes)))

has_identity()

has_identity will return true if the authentication credentials have an associated identity and false if they don’t.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "has_identity": null }'

// Not available in this language yet.

System.out.println(
   client.query(HasIdentity()).get());

result, _ := client.Query(f.HasIdentity())

fmt.Println(result)

// Not available in this language yet.

# Not available in this language yet.

# Not available in this language yet.

// Not available in this language yet.

client.query(q.HasIdentity())
  .then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{ "resource": false }

=> false

=> false

=> false

=> false

=> false

=> false

=> false

=> false

String Functions

concat

concat( Expression Strings, [Expression Separator] )

Description

The concat function returns a string which has joined a list of strings into a single string.

Parameters

Argument Description Special Notes
Strings An array of strings to join Required
Separator This value will be placed between each joined string. Optional - defaults to ""

Returns

A string value

Examples

The query below executes an array of independent concat operations and returns the results in an array. The result array position matches the execution array position. The first operation takes the array of strings containing “fire” and “man” and joins the strings to make the string “fireman” placing it into the top position of the result array. The second operation in the execution array has an array of strings containing “Hen” and “Wen” as its first argument and a separator of “ “ (space) as its second argument. The result of ‘Hen Wen’ is placed into the second position of the result array.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "concat": [ "Hen", "Wen" ], "separator": " " }'

client.Query(Concat(Arr("Hen", "Wen"), " "));

System.out.println(
     client.query(Concat(Arr(Value("Hen"), Value("Wen")), Value(" ")))
     .get());

result, _ := client.Query(f.Concat(f.Arr{"Hen", "Wen"}, f.Separator(" ")))

fmt.Println(result)

client.query(Concat(Arr("Hen", "Wen"), " "))

client.query(q.concat(["Hen", "Wen"], " "))

$client.query do
  concat ['Hen', 'Wen'], ' '
end

client.query(Concat("Hen", "Wen", separator: " "))

client.query(q.Concat(["Hen", "Wen"], " "))
  .then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{ "resource": "Hen Wen" }

=> "Hen Wen"

=> "Hen Wen"

=> Hen Wen

=> "Hen Wen"

=> "Hen Wen"

=> "Hen Wen"

=> "Hen Wen"

=> Hen Wen

Related References

casefold

casefold( Expression Strings, [Expression Separator] )

Description

The casefold function returns a normalized string. When strings are transformed into their normlized forms, then canonical-equivalent strings will have precisely the same binary representation. Then, a binary comparison function such as equals can compare two strings for case-insensitive matching. The Unicode Standard provides well-defined normalization forms (see section 5.18 “Case Mappings”). By default, FaunaDB uses NKFCCaseFold as recommended by the W3C, but provides NFKCCaseFold, NFC, NFD, NFKC, NFKD.

Parameters

Argument Description Special Notes
Strings An array of strings to casefold Required
Normalizer The name of the normalizer method to use. Must be one of 'NFKCCaseFold', 'NFC', 'NFD', 'NFKC', 'NFKD'. Optional, defaults to `NFKCCaseFold`

Returns

A string value

Examples

The query below converts the string “Hen Wen” to “hen wen” to support case-insensitive matching.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "casefold": "Hen Wen" }'

client.Query(Casefold("Hen Wen"));

System.out.println(
       client.query(Casefold(Value("Hen Wen")))
       .get());

result, _ := client.Query(f.Casefold("Hen Wen"))

fmt.Println(result)

client.query(Casefold("Hen Wen"))

client.query(q.casefold("Hen Wen"))

$client.query do
  casefold 'Hen Wen'
end

client.query(Casefold("Hen Wen"))

client.query(q.Casefold("Hen Wen"))
  .then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{ "resource": "hen wen" }

=> "hen wen"

=> "hen wen"

=> hen wen

=> "hen wen"

=> "hen wen"

=> "hen wen"

=> "hen wen"

=> hen wen

Related References

Time and Date

Fauna has two special data types dealing with dates and times. The first data type is date which stores a calendar date. The second is a timestamp (ts) which stores an instant in time expressed as a calendar date and time of day. Timestamp can safely store nanoseconds precision, but be careful as many operating system clocks provide only microsecond precision. All Timestamps are stored in UTC. If a timestamp is inserted with a timezone (TZ), it will be canonicalized to UTC and the local timezone will not be stored. The following functions allow the manipulation of dates and timestamps.

Date


Date( str )

Date( str )

Date( str )

Date( str )

date( str )

date str

DateFn( str )

Date( str )

Description

The Date function constructs a date type from an ISO 8601 formatted string.

Parameters

Argument Type Definition and Requirements
str String An ISO 8601 date formatted string.

Returns

A Date type which represents the converted string.

Examples

The query below returns a date constructed from the provided string.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "date": "1970-01-01" }'

client.Query(Date("1970-01-01"));

System.out.println( client.query(Date(Value("1970-01-01"))) .get());

result, _ := client.Query(f.Date("1970-01-01"))

fmt.Println(result)

client.query(Date("1970-01-01"))

client.query(q.date("1970-01-01"))

$client.query do
  date '1970-01-01'
end

client.query(DateFn(string: "1970-01-01"))

client.query(q.Date("1970-01-01"))
  .then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{ "resource": { "@date": "1970-01-01" } }

=> { "@date": "1970-01-01" }

=> 1970-01-01

=> {0 62135596800 <nil>}

=> { "@date": "1970-01-01" }

=> { "@date": "1970-01-01" }

=> { "@date": "1970-01-01" }

=> { "@date": "1970-01-01" }

=> FaunaDate { value: '1970-01-01' }

Related References

Epoch


Epoch( num, unit )

Epoch( num, unit )

Epoch( num, unit )

Epoch( num, unit )

epoch(0, unit )

epoch  num, unit

Epoch( num, unit )

Epoch( num, unit )

Description

The Epoch function constructs a timestamp type relative to the epoch (1970-01-01T00:00:00Z). The num argument must be an integer value. The unit argument must be one of the following: “second”, “millisecond”, “microsecond”, “nanosecond”.
The Epoch adds num to offset defined in units and returns a timestamp.

Parameters

Argument Type Definition and Requirements
num Number A mathematical integer value specifying the offset from epoch.
unit String One of the following 4 strings “second”, “millisecond”, “microsecond”, “nanosecond” indicating the units the offset is in.

Returns

A timestamp which represents epoch plus the offset.

Examples

The query below adds 0 seconds to the epoch (1970-01-01T00:00:00Z) and returns a timestamp.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "epoch": 0, "unit": "second" }'

client.Query(Epoch(0, "second"));

System.out.println(
       client.query(Epoch(Value(0), TimeUnit.SECOND))
       .get());

result, _ := client.Query(f.Epoch(0, f.TimeUnitSecond))

fmt.Println(result)

client.query(Epoch(0, "second"))

client.query(q.epoch(0, "second"))

$client.query do
  epoch 0, 'second'
end

client.query(Epoch(0, "second"))

client.query(q.Epoch(0, "second"))
  .then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{ "resource": { "@ts": "1970-01-01T00:00:00Z" } }

=> { "@ts": "1970-01-01T00:00:00Z" }

=> 1970-01-01T00:00:00Z

=> {0 62135596800 <nil>}

=> { "@ts": "1970-01-01T00:00:00Z" }

=> { "@ts": "1970-01-01T00:00:00Z" }

=> { "@ts": "1970-01-01T00:00:00Z" }

=> { "@ts": "1970-01-01T00:00:00Z" }

=> FaunaTime { value: '1970-01-01T00:00:00Z' }

Related References

Wikipedia ISO 8601

Time


Time( str )

Time( str )

Time( str )

Time( str )

Time( str )

Time str

Time( str )

Time( str )

Description

The Time function constructs a timestamp type from an ISO 8601 string. The special string “now” may be used to construct a time from the current request’s transaction time. Multiple references to “now” within the same transaction will produce the same timestamp. The current transaction time will be the same on all nodes that participate in the transaction. When doing a temporal query “now” will mean the current time of the query, not the current time.

Parameters

Argument Type Definition and Requirements
str String An ISO 8601 date/time formatted string, or the string “now”.

Returns

A timestamp which represents the converted string.

Examples

The query below returns a timestamp constructed from the provided string.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "time": "1970-01-01T00:00:00+00:00" }'

client.Query(Time("1970-01-01T00:00:00+00:00"));

System.out.println(
     client.query(Time(Value("1970-01-01T00:00:00+00:00"))
     ).get());

result, _ := client.Query(f.Time("1970-01-01T00:00:00+00:00"))

fmt.Println(result)

client.query(Time("1970-01-01T00:00:00+00:00"))

client.query(q.time("1970-01-01T00:00:00+00:00"))

$client.query do
  time '1970-01-01T00:00:00+00:00'
end

client.query(Time(fromString: "1970-01-01T00:00:00+00:00"))

client.query(q.Time("1970-01-01T00:00:00+00:00"))
  .then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{ "resource": { "@ts": "1970-01-01T00:00:00Z" } }

=> { "@ts": "1970-01-01T00:00:00Z" }

=> 1970-01-01T00:00:00Z

=> {0 62135596800 <nil>}

=> { "@ts": "1970-01-01T00:00:00Z" }

=> { "@ts": "1970-01-01T00:00:00Z" }

=> { "@ts": "1970-01-01T00:00:00Z" }

=> { "@ts": "1970-01-01T00:00:00Z" }

=> FaunaTime { value: '1970-01-01T00:00:00Z' }

Related References

Wikipedia ISO 8601

Mathematical Functions

Abs


Not available in this language yet.

Abs( value )

Abs( value )

Abs( value )

Not available in this language yet.

Not available in this language yet.

Not available in this language yet.

Abs( value )

Description

The Abs function is used to get the absolute value of a number.

Parameters

Argument Type Definition and Requirements
value Number Take the absolute value of this argument.

Returns

A number which is the absolute value of a numeric input argument.

Examples

The query below returns the absolute value of -100.


System.out.println(
        client.query(
                Abs(Value(-100)))
                .get());

=> 100

Related References

Acos


Not available in this language yet.

Acos( value )

Acos( value )

Acos( value )

Not available in this language yet.

Not available in this language yet.

Not available in this language yet.

Acos( value )

Description

The Acos function is a trigonometric function which calculates ratios of the lengths of the sides of right triangles. The Acos returns the arc cosine of a number.

Parameters

Argument Type Definition and Requirements
value Number Take the absolute value of this value.

Returns

A number which is the arc cosine of value.

Examples

The query below returns the arc cosine of 0.5.


System.out.println(
        client.query(
                Acos(Value(0.5)))
                .get());

=> 1.0471975511965979

Related References

Add


Add( value_1, value_2, ... )

Add( value_1, value_2, ... )

Add( value_1, value_2, ... )

Add( value_1, value_2, ... )

add( value_1, value_2, ... )

add  value_1, value_2, ...

Add( value_1, value_2, ... )

Add( value_1, value_2, ... )

Description

The Add function returns the sum of its numeric arguments. It can take a single value or a list of values. Providing a single number returns the number.

Parameters

Argument Type Definition and Requirements
value Number One or more numbers to sum.

Returns

A number which is the sum of all values.

Examples

The query below returns the sum of 100 and 10.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "add": [ 100, 10 ] }'

client.Query(Add(100, 10));

System.out.println(
    client.query(Add(Value(100), Value(10)))
    .get());

result, _ := client.Query(f.Add(100, 10))

fmt.Println(result)

client.query(Add(100, 10))

client.query(q.add(100, 10))

$client.query do
  add 100, 10
end

client.query(Add(100, 10))

client.query(q.Add(100, 10))
  .then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{ "resource": 110 }

=> 110

=> 110

=> 110

=> 110

=> 110

=> 110

=> 110

=> 110

Related References

Asin


Not available in this language yet.

Asin( value )

Asin( value )

Asin( value )

Not available in this language yet.

Not available in this language yet.

Not available in this language yet.

Asin( value )

Description

The Asin function is a trigonometric function which calculates ratios of the lengths of the sides of right triangles. The Asin returns the arc sine of a number.

Parameters

Argument Type Definition and Requirements
value Number Take the arc sine of this value.

Returns

A number which is the arc sine of value.

Examples

The query below returns the arc sine of 0.5.


System.out.println(
        client.query(
                Asin(Value(0.5)))
                .get());

=> 0.5235987755982989

Related References

Atan


Not available in this language yet.

Atan( value )

Atan( value )

Atan( value )

Not available in this language yet.

Not available in this language yet.

Not available in this language yet.

Atan( value )

Description

The Atan function is a trigonometric function which calculates ratios of the lengths of the sides of right triangles. The Atan returns the arc tangent of a number.

Parameters

Argument Type Definition and Requirements
value Number Take the arc tangent of this value.

Returns

A number which is the arc tangent of value.

Examples

The query below returns the arc tangent of 0.5.


System.out.println(
        client.query(
                Atan(Value(0.5)))
                .get());

=> 0.4636476090008061

Related References

BitAnd


Not available in this language yet.

BitAnd( value_1, value_2, ... )

BitAnd( value_1, value_2, ... )

BitAnd( value_1, value_2, ... )

Not available in this language yet.

Not available in this language yet.

Not available in this language yet.

BitAnd( value_1, value_2, ... )

Description

The BitAnd function returns the bit to the result if the bit exists in all numbers. The arguments must be numbers, and fractional values will be truncated before the operation is applied. The result is the bitwise “and” of all the arguments.

Parameters

Argument Type Definition and Requirements
value List of Numbers A single value or a list of values to bitand.

Returns

A number which is the bitand of all values.

Examples

The query below executes an array of independent bitwise “and” operations and returns the answer in the result array. The result array position matches the position in the execution array.


System.out.println(
        client.query( Arr(
                BitAnd(Value(0),Value(0)),
                BitAnd(Value(1),Value(0)),
                BitAnd(Value(1),Value(1)),
                BitAnd(Value(7),Value(3))
        )) .get());

=> [
  0, 
  0, 
  1, 
  3
]

Related References

BitNot


Not available in this language yet.

BitNot( value )

BitNot( value )

BitNot( value )

Not available in this language yet.

Not available in this language yet.

Not available in this language yet.

BitNot( value )

Description

The BitNot function returns the Two’s Complement of a number. The argument must be a number, and fractional values will be truncated before the operation is applied.

Parameters

Argument Type Definition and Requirements
value Number A single value to take the two’s complement.

Returns

A number which is the two’s complement of the value.

Examples

The query below executes an array of independent bitwise “not” operations and returns results in the result array. The result array position matches the position in the execution array.


System.out.println(
        client.query( Arr(
                BitNot(Value(0)),
                BitNot(Value(1)),
                BitNot(Value(7))
        )).get());

=> [
  -1, 
  -2, 
  -8
]

Related References

BitOr


Not available in this language yet.

BitOr( value_1, value_2, ... )

BitOr( value_1, value_2, ... )

BitOr( value_1, value_2, ... )

Not available in this language yet.

Not available in this language yet.

Not available in this language yet.

BitOr( value_1, value_2, ... )

Description

The BitOr function returns the bit to the result if the bit exists in any argument. The arguments must be numbers, and the fractional portion will be truncated before the “or” operation is applied. The result is the bitwise “or” of all the arguments.

Parameters

Argument Type Definition and Requirements
value List of Numbers A single value or a list of values to bitwise or.

Returns

A number which is the bitwise “or” of all values.

Examples

The query below executes an array of independent bitwise “or” operations and returns results in the result array. The result array position matches the position in the execution array.


System.out.println(
        client.query( Arr(
                BitOr(Value(0), Value(0)),
                BitOr(Value(1), Value(0)),
                BitOr(Value(1), Value(1)),
                BitOr(Value(6), Value(3))
        )).get());

=> [
   0, 
   1, 
   1, 
   7
]

Related References

BitXor


Not available in this language yet.

BitXor( value_1, value_2, ... )

BitXor( value_1, value_2, ... )

BitXor( value_1, value_2, ... )

Not available in this language yet.

Not available in this language yet.

Not available in this language yet.

BitXor( value_1, value_2, ... )

Description

The BitXor function returns the bit to the result if the bit exists in only one argument. The arguments must be numbers, and the fractional portion will be truncated before the “xor” operation is applied. The result is the bitwise exclusive “or” of all the arguments.

Parameters

Argument Type Definition and Requirements
value List of Numbers A single value or a list of values to bitwise exclusive or.

Returns

A number which is the exclusive “or” of all values.

Examples

The query below executes an array of independent bitwise exclusive “or” operations and returns results in the result array. The result array position matches the position in the execution array.


System.out.println(
        client.query( Arr(
                BitXor(Value(0), Value(0)),
                BitXor(Value(1), Value(0)),
                BitXor(Value(1), Value(1)),
                BitXor(Value(6), Value(3))
        )).get());

=> [
  0, 
  1, 
  0, 
  5
]

Related References

Ceil


Not available in this language yet.

Ceil( value )

Ceil( value )

Ceil( value )

Not available in this language yet.

Not available in this language yet.

Not available in this language yet.

Ceil( value )

Description

The Ceil function returns a value that is greater than or equal to the argument and is equal to the nearest mathematical integer.

Parameters

Argument Type Definition and Requirements
value Numbers The ceil of this value.

Returns

A number which is the ceil of value.

Examples

The query below executes an array of independent ceil operations and returns each answer in the result array. The result array position matches the position in the execution array.


System.out.println(
        client.query( Arr(
                Ceil(Value(7.0)),
                Ceil(Value(1.11)),
                Ceil(Value(2.99))
        )).get());

=> [
  7.0, 
  2.0, 
  3.0
]

Related References

Cos


Not available in this language yet.

Cos( value )

Cos( value )

Cos( value )

Not available in this language yet.

Not available in this language yet.

Not available in this language yet.

Cos( value )

Description

The Cos function is a trigonometric function which calculates ratios of the lengths of the sides of right triangles. The Cos returns the cosine of a number.

Parameters

Argument Type Definition and Requirements
value Number Take the cosine of this value.

Returns

A number which is the cosine of value.

Examples

The query below executes an array of independent cosine operations and returns each answer in the result array. The result array position matches the position in the execution array.


System.out.println(
        client.query(
                Cos(Value(0.5)))
                .get());

=> 0.8775825618903728

Related References

Cosh


Not available in this language yet.

Cosh( value )

Cosh( value )

Cosh( value )

Not available in this language yet.

Not available in this language yet.

Not available in this language yet.

Cosh( value )

Description

The Cosh function is a trigonometric function which calculates ratios of the lengths of the sides of right triangles. The Cosh returns the hyperbolic cosine of a number.

Parameters

Argument Type Definition and Requirements
value Number Take the hyperbolic cosine of this value.

Returns

A number which is the hyperbolic cosine of value.

Examples

The query below executes a hyperbolic cosine operations of the value 0.5.


System.out.println(
        client.query(
                Cosh(Value(0.5)))
                .get());

=> 1.1276259652063807

Related References

Degrees


Not available in this language yet.

Degrees( value )

Degrees( value )

Degrees( value )

Not available in this language yet.

Not available in this language yet.

Not available in this language yet.

Degrees( value )

Description

The Degrees function converts a specified number from radians to degrees. The argument is an angle measured in radians, which is converted to an approximate angle measured in degrees.

Parameters

Argument Type Definition and Requirements
value Number Take the value specified in radians.

Returns

A number which is the given angle measured in degrees.

Examples

The query below takes 0.5 radians and converts it to approximately 28.6 degrees.


System.out.println(
        client.query(
                Degrees(Value(0.5)))
                .get());

=> 28.64788975654116

Related References

Divide


Divide( value_1, value_2, ... )

Divide( value_1, value_2, ... )

Divide( value_1, value_2, ... )

divide( value_1, value_2, ... )

divide value_1, value_2, ...

Divide( value_1, value_2, ... )

Divide( value_1, value_2, ... )

Description

The Divide function will compute the quotient of two or more numbers.

Attempting to divide an empty list will result in an “invalid argument” error.

Attempting to divide any value by zero will result in a “invalid argument” error.

Parameters

Argument Type Definition and Requirements
value Number One or more numbers to divide.

Returns

A number which is the result of dividing two or more numbers.

Examples

The query below executes two equivalent division operations. The first example provides the Divide function a list of numbers. The second equivalent operation first divides 10 by 5, the takes the result of that operation and divides it by 2.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "divide": [ 10, 5, 2 ] }'

client.Query(Divide(10, 5, 2));

System.out.println(
       client.query(Divide(Value(10), Value(5), Value(2)))
               .get());

result, _ := client.Query(f.Divide(10, 5, 2))

fmt.Println(result)

client.query(Divide(10, 5, 2))

client.query(q.divide(10, 5, 2))

$client.query do
  divide 10, 5, 2
end

client.query(Divide(10, 5, 2))

client.query(q.Divide(10, 5, 2))
  .then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{ "resource": 1 }

=> 1

=> 1

=> 1

=> 1

=> 1

=> 1

=> 1

=> 1

is equivalent to:


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "divide": [ { "divide": [ 10, 5 ] }, 2 ] }'

client.Query(Divide(Divide(10, 5), 2));

System.out.println(
     client.query(Divide(Divide(Value(10), Value(5)), Value(2)))
     .get());

result, _ := client.Query(f.Divide(f.Divide(10, 5), 2))

fmt.Println(result)

client.query(Divide(Divide(10, 5), 2))

client.query(q.divide(q.divide(10, 5), 2))

$client.query do
  divide divide(10, 5), 2
end

client.query(Divide(Divide(10, 5), 2))

client.query(q.Divide(q.Divide(10, 5), 2))
  .then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{ "resource": 1 }

=> 1

=> 1

=> 1

=> 1

=> 1

=> 1

=> 1

=> 1

Related References

Exp


Not available in this language yet.

Exp( value )

Exp( value )

Exp( value )

Not available in this language yet.

Not available in this language yet.

Not available in this language yet.

Exp( value )

Description

The Exp function returns Euler’s number e (approximately 2.71828) raised to a power provided as the operand.

Parameters

Argument Type Definition and Requirements
value Number The power to raise e to.

Returns

A number which is the result of raising e to a power.

Examples

The query in the following example returns the Euler’s number raised to the power of 1.5.


System.out.println(
        client.query(
                Exp(Value(1.5)))
                .get());

=> 4.4816890703380645

Hypot


Not available in this language yet.

Hypot( a, b )

Hypot( a, b )

Hypot( a, b )

Not available in this language yet.

Not available in this language yet.

Not available in this language yet.

Hypot( a, b )

Description

The Hypot function calculates the length of the hypotenuse of a right-angle triangle given the length of the other two sides.

Parameters

Argument Type Definition and Requirements
a Number The length of one side of the right triangle.
b Number Optional - The length of the second side of the right triangle. If this argument is not provided, the operation assumes an isosceles right triangle where a = b.

Returns

A number which is the length of the hypotenuse of a right triangle.

Examples

The query below executes an array of independent hypotenuse calculations and returns the results in an array. The result array position matches the execution array position. The first operation takes the value 3.0 for the length of both sides of the right triangle (i.e., an isosceles right triangle) and returns the length of the hypotenuse. The result 4.242640687119285 is in the top position of the execution array. The second operation calculates the hypotenuse length using side lengths of 3 and 4. The resulting hypotenuse length of 5.0 is placed in the second position of the execution array.


System.out.println(
        client.query( Arr(
                Hypot(Value(3.0)),
                Hypot(Value(3),Value(4)),
                Hypot(Value(3.5), Value(5.5))
        )).get());

=> [
   4.242640687119285, 
   5.0, 
   6.519202405202649
 ]

Floor


Not available in this language yet.

Floor( value )

Floor( value )

Floor( value )

Not available in this language yet.

Not available in this language yet.

Not available in this language yet.

Floor( value )

Description

The Floor function returns the largest value that is less than or equal to the argument and is equal to a mathematical integer.

Parameters

Argument Type Definition and Requirements
value Number Take the floor of this value.

Returns

A number which is the result of the Floor operation.

Examples

The query below executes an array of independent floor operations and returns the results in an array. The result array position matches the execution array position. The top operation in the execution array, floor of 7.0, returns a long value of 7 in the top position of the result array.


System.out.println(
        client.query( Arr(
                Floor(Value(7.0)),
                Floor(Value(1.11)),
                Floor(Value(2.99))
        )).get());

=> [
   7.0, 
   1.0, 
   2.0
]

Ln


Not available in this language yet.

Ln( value )

Ln( value )

Ln( value )

Not available in this language yet.

Not available in this language yet.

Not available in this language yet.

Ln( value )

Description

The Ln function returns the natural logarithm (base e) of the operand.

Parameters

Argument Type Definition and Requirements
value Number Take the ln of this value.

Returns

A number which is the result of the Ln operation.

Examples

The query in the following example returns the logarithm base e of the value 0.5:


System.out.println(
        client.query(
                Ln(Value(0.5)))
                .get());

=> -0.6931471805599453

Log


Not available in this language yet.

Log( value )

Log( value )

Log( value )

Not available in this language yet.

Not available in this language yet.

Not available in this language yet.

Log( value )

Description

The Log function returns the natural logarithm (base e) of the operand.

Parameters

Argument Type Definition and Requirements
value Number Take the Log of this value.

Returns

A number which is the result of the Log operation.

Examples

The query in the following example returns the logarithm base 10 of the value 0.5.


System.out.println(
        client.query(
                Log(Value(0.5)))
                .get());

=> -0.3010299956639812

Max


Not available in this language yet.

Max( value_1, value_2, ... )

Max( value_1, value_2, ... )

Max( value_1, value_2, ... )

Not available in this language yet.

Not available in this language yet.

Not available in this language yet.

Max( value_1, value_2, ... )

Description

The Max function returns the largest value in a list of numbers.

Parameters

Argument Type Definition and Requirements
value List of Numbers A single value or a list of values.

Returns

A number which is the maximum value from the value list.

Examples

The query below executes an array of independent max operations and returns the results in an array. The result array position matches the execution array position. The top operation in the execution array, max of the values 1, 5, and 22, returns a long value of 22 in the top position of the result array.


System.out.println(
        client.query( Arr(
                Max(Value(1), Value(5), Value(22)),
                Max(Value(1), Value(0), Value(3), Value(-1)),
                Max(Value(-1), Value(12), Value(3), Value(-1)),
                Max(Value(10))
        )).get());

=> [
  22, 
  3, 
  12, 
  10
]

Min


Not available in this language yet.

Min( value_1, value_2, ... )

Min( value_1, value_2, ... )

Min( value_1, value_2, ... )

Not available in this language yet.

Not available in this language yet.

Not available in this language yet.

Min( value_1, value_2, ... )

Description

The Min function returns the smallest value in a list of numbers.

Parameters

Argument Type Definition and Requirements
value List of Numbers A single value or a list of values.

Returns

A number which is the minimum value from the value list.

Examples

The query below executes an array of independent min operations and returns the results in an array. The result array position matches the execution array position. The top operation in the execution array, minimum of the values 1, 5, and 22, returns a long value of 1 in the top position of the result array.


System.out.println(
        client.query( Arr(
                Min(Value(1), Value(5), Value(22)),
                Min(Value(1), Value(0), Value(3), Value(-1)),
                Min(Value(-1), Value(12), Value(3), Value(-1)),
                Min(Value(10))
        )).get());

=> [
 1, 
 -1, 
 -1, 
 10
]

Modulo


Modulo( value_1, value_2, ... )

Modulo( value_1, value_2, ... )

Modulo( value_1, value_2, ... )

Modulo( value_1, value_2, ... )

modulo( value_1, value_2, ... )

modulo value_1, value_2, ...

Modulo( value_1, value_2, ... )

Modulo( value_1, value_2, ... )

Description

The Modulo function computes the remainder after division on a list of numbers. Providing a single operand returns the operand.

Attempting to call modulo with an empty array will result in the error “Non-empty array expected.” Check to make sure at least one argument is passed to modulo function.

Attempting to compute the remainder of a division by zero will result in the error “Illegal division by zero.”

Parameters

Argument Type Definition and Requirements
value List of Numbers A single value or a list of values.

Returns

A number which is the modulo from the value list.

Examples


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "modulo": [ 10, 5, 2 ] }'

client.Query(Modulo(10, 5, 2));

System.out.println(
       client.query(Modulo(Value(10), Value(5), Value(2)))
       .get());

result, _ := client.Query(f.Modulo(10, 5, 2))

fmt.Println(result)

client.query(Modulo(10, 5, 2))

client.query(q.modulo(10, 5, 2))

$client.query do
  modulo 10, 5, 2
end

client.query(Modulo(10, 5, 2))

client.query(q.Modulo(10, 5, 2))
  .then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{ "resource": 0 }

=> 0

=> 0

=> 0

=> 0

=> 0

=> 0

=> 0

=> 0

is equivalent to:


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "modulo": [ { "modulo": [ 10, 5 ] }, 2 ] }'

client.Query(Modulo(Modulo(10, 5), 2));

System.out.println(
       client.query(Modulo(Modulo(Value(10), Value(5)), Value(2)))
       .get());

result, _ := client.Query(f.Modulo(f.Modulo(10, 5), 2))

fmt.Println(result)

client.query(Modulo(Modulo(10, 5), 2))

client.query(q.modulo(q.modulo(10, 5), 2))

$client.query do
  modulo modulo(10, 5), 2
end

client.query(Modulo(Modulo(10, 5), 2))

client.query(q.Modulo(q.Modulo(10, 5), 2))
  .then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{ "resource": 0 }

=> 0

=> 0

=> 0

=> 0

=> 0

=> 0

=> 0

=> 0

Multiply


Multiply( value_1, value_2, ... )

Multiply( value_1, value_2, ... )

Multiply( value_1, value_2, ... )

Multiply( value_1, value_2, ... )

multiply( value_1, value_2, ... )

multiply  value_1, value_2, ...

Multiply( value_1, value_2, ... )

Multiply( value_1, value_2, ... )

Description

The Multiply function computes the product of a list of numbers. Providing a single number returns the number.

Attempting to call multiply without any arguments will result in the error “Non-empty array expected.” Check to make sure at least one argument is passed to the multiply function.

Parameters

Argument Type Definition and Requirements
value List of Numbers A single value or a list of values.

Returns

A number which is the product of the list of values.

Examples


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "multiply": [ 100, 10 ] }'

client.Query(Multiply(100, 10));

System.out.println(
       client.query(Multiply(Value(100), Value(10)))
       .get());

result, _ := client.Query(f.Multiply(100, 10))

fmt.Println(result)

client.query(Multiply(100, 10))

client.query(q.multiply(100, 10))

$client.query do
  multiply 100, 10
end

client.query(Multiply(100, 10))

client.query(q.Multiply(100, 10))
  .then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{ "resource": 1000 }

=> 1000

=> 1000

=> 1000

=> 1000

=> 1000

=> 1000

=> 1000

=> 1000

Pow


Not available in this language yet.

Pow( value, exponent)

Pow( value, exponent)

Pow( value, exponent)

Not available in this language yet.

Not available in this language yet.

Not available in this language yet.

Pow( value, exponent)

Description

The Pow function raises its first numeric argument, the base, to the power of its second numeric argument, the exponent.

Parameters

Argument Type Definition and Requirements
base Number The base.
exponent Number The exponent.

Returns

The result of raising a number (base) to the power of another number (exponent).

Examples


System.out.println(
        client.query( Arr(
                Pow(Value(2), Value(3)),
                Pow(Value(5), Value(2))
        )).get());

=> [8.0, 25.0]

Radians


Not available in this language yet.

Radians( value )

Radians( value )

Radians( value )

Not available in this language yet.

Not available in this language yet.

Not available in this language yet.

Radians( value )

Description

The Radians function translates a specified number from degrees to radians. The argument is an angle measured in degrees, which is converted to the approximated angle measured in radians.

Parameters

Argument Type Definition and Requirements
value Number Take the value specified in degrees.

Returns

A number which is the given angle measured in radians.

Examples

The query in the following example returns the radians of 2 degrees:


System.out.println(
        client.query(
                Radians(Value(2))
        ).get());

=> 0.03490658503988659

Round


Not available in this language yet.

Round( value, [ precision ]  )

Round( value, [ precision ]  )

Round( value, [ precision ]  )

Not available in this language yet.

Not available in this language yet.

Not available in this language yet.

Round( value, [ precision ]  )

Description

The Round function returns a number which is the nearest mathematic value of the operand to the specified precision as a double value.

Parameters

Argument Type Definition and Requirements
value Number A number to be rounded with a specific precision.
precision Number Optional - Defines how many digits to the right or left of the decimal place will be returned. The default precision is 2 which will return up to the hundredths decimal places. A positive precision specifies digits to the right of the decimal point. A negative precision specifies digits to the left of the decimal point. A zero precision rounds the fractional part of the number.

Returns

A number with its precision modified.

Examples

The query below executes an array of independent rounding operations and returns the results in an array. The result array position matches the position of the execution array position. The first operation takes the value 1234.5678 and by default rounds the value to 2 digits to the right of the decimal point. The result is 1234.57 which is in the top position of the result array. The second operation rounds the value 1234 to a precision of -2. This is two digits to the left of the decimal point, the hundreds position. The operations to the left of the decimal point are zero filled less than the specified precision. The result of 1200 is placed in the third position of the result array.


System.out.println(
        client.query( Arr(
                Round(Value(1234.5678)),
                Round(Value(1234), Value(-2)),
                Round(Value(1234.5678), Value(2)),
                Round(Value(1234.5678), Value(-2)),
                Round(Value(5678.1234), Value(3)),
                Round(Value(1234), Value(-3)),
                Round(Value(5678.1234), Value(-3))
        )).get());

=> [
   1234.57, 
   1200, 
   1234.57, 
   1200.0, 
   5678.123, 
   1000, 
   6000.0
]

Sign


Not available in this language yet.

Sign( value )

Sign( value )

Sign( value )

Not available in this language yet.

Not available in this language yet.

Not available in this language yet.

Sign( value )

Description

The Sign function returns the sign of the argument as a numeric value.

Parameters

Argument Type Definition and Requirements
value Number Determine the sign of this number.

Returns

Long Values

  • 1 when the value of the argument is positive
  • 0 when the value of the argument is zero
  • -1 when the value of the argument is negative

Double Values

  • -1 when the value of the argument is less than zero
  • 1 when the value is greater than or equal to zero or NaN

Examples

The query below executes an array of independent sign operations and returns the results in an array. The result array position matches the execution array position. The first sign operation on the value 3 returns 1 for a positive number. The second operation returns zero for neither a positive nor negative number. The third sign operation on the value -3 returns -1 for a negative number.


System.out.println(
        client.query( Arr(
                Sign(Value(3)),
                Sign(Value(0)),
                Sign(Value(-3))
        )).get());

=> [
  1, 
  0, 
  -1
]

Sin


Not available in this language yet.

Sin( value )

Sin( value )

Sin( value )

Not available in this language yet.

Not available in this language yet.

Not available in this language yet.

Sin( value )

Description

The Sin function is a trigonometric function which calculates ratios of the lengths of the sides of right triangles. The Sin returns the sine of a number, which is the ratio of the side opposite to an acute angle in a right triangle to the hypotenuse.

Parameters

Argument Type Definition and Requirements
value Number Take the sine of this value.

Returns

A number which is the sine of the value.

Examples

The query in the following example returns the sin of 5:


System.out.println(
        client.query(
                Sin(Value(5))
        ).get());

=> -0.9589242746631385

Related References

Sinh


Not available in this language yet.

Sinh( value )

Sinh( value )

Sinh( value )

Not available in this language yet.

Not available in this language yet.

Not available in this language yet.

Sinh( value )

Description

A trigonometric function that returns the hyperbolic sine of a number.

Parameters

Argument Type Definition and Requirements
value Number Take the hyperbolic sine of this value.

Returns

A number which is the hyperbolic sine of value.

Examples

The query in the following example returns the sinh of 2:


System.out.println(
        client.query(
                Sinh(Value(2))
        ).get());

=> 3.626860407847019

Related References

Sqrt


Not available in this language yet.

Sqrt( value )

Sqrt( value )

Sqrt( value )

Not available in this language yet.

Not available in this language yet.

Not available in this language yet.

Sqrt( value )

Description

The Sqrt function returns the positive square root of a number value.

Parameters

Argument Type Definition and Requirements
value Number Take the square root of value.

Returns

A number which is the given angle measured in degrees.

Examples

The query in the following example returns the square root of 16:


System.out.println(
        client.query(
                Sqrt(Value(16))
        ).get());

=> 4.0

Related References

Subtract


Subtract( value_1, value_2, ... )

Subtract( value_1, value_2, ... )

Subtract( value_1, value_2, ... )

Subtract( value_1, value_2, ... )

subtract( value_1, value_2, ... )

subtract value_1, value_2, ...

Subtract( value_1, value_2, ... )

Subtract( value_1, value_2, ... )

Description

The Subtract function returns the difference of a list of numbers.

Parameters

Argument Type Definition and Requirements
value Number Take the difference of values.

Returns

A number which is the difference.

Examples

The query in the following example returns the square root of 16:


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "subtract": [ 100, 10 ] }'

client.Query(Subtract(100, 10));

System.out.println(
       client.query(Subtract(Value(100), Value(10)))
       .get());

result, _ := client.Query(f.Subtract(100, 10))

fmt.Println(result)

client.query(Subtract(100, 10))

client.query(q.subtract(100, 10))

$client.query do
  subtract 100, 10
end

client.query(Subtract(100, 10))

client.query(q.Subtract(100, 10))
  .then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{ "resource": 90 }

=> 90

=> 90

=> 90

=> 90

=> 90

=> 90

=> 90

=> 90

Related References

Tan


Not available in this language yet.

Tan( value )

Tan( value )

Tan( value )

Not available in this language yet.

Not available in this language yet.

Not available in this language yet.

Tan( value )

Description

A trigonometric function that returns the tangent of a number, which is the ratio of the side opposite to an acute angle in a right triangle to the side adjacent.

Parameters

Argument Type Definition and Requirements
value Number Take the tangent of value.

Returns

A number which is the tangent of the value.

Examples

The query in the following example returns the tangent of 1.5:


System.out.println(
        client.query(
                Tan(Value(1.5))
        ).get());

=> 14.101419947171719

Related References

Tanh


Not available in this language yet.

Tanh( value )

Tanh( value )

Tanh( value )

Not available in this language yet.

Not available in this language yet.

Not available in this language yet.

Tanh( value )

Description

A trigonometric function that returns the hyperbolic tangent of a number.

Parameters

Argument Type Definition and Requirements
value Number Take the hyperbolic tangent of this value.

Returns

A number which is the hyperbolic tangent of the value.

Examples

The query in the following example returns the hyperbolic tangent of 1.5:


System.out.println(
        client.query(
                Tanh(Value(1.5))
        ).get());

=> 0.9051482536448664

Related References

Trunc


Not available in this language yet.

Trunc( value, [precision] )

Trunc( value, [precision] )

Trunc( value, [precision] )

Not available in this language yet.

Not available in this language yet.

Not available in this language yet.

Trunc( value, [precision] )

Description

The Trunc function returns a number which is the nearest mathematic value less than or equal to the operand to the specified precision as a double value.

Parameters

Argument Type Definition and Requirements
value Number A number to be truncated with a specific precision.
precision Number Optional - Defines how many digits to the right or left of the decimal place will be returned. The default precision is 2 which will return up to the hundredths decimal places. A positive precision specifies digits to the right of the decimal point. A negative precision specifies digits to the left of the decimal point. A zero precision truncates the fractional part of the number.

Returns

A number with its precision modified.

Examples

The query below executes an array of independent truncation operations and returns the results in an array. The result array position matches the execution array position. The first operation takes the value 1234.5678 and by default truncates the value to 2 digits to the right of the decimal point. The result is 1234.56 which is in the top position of the result array. The second operation truncates the value 1234 to a precision of -2. This is two digits to the left of the decimal point, the hundreds position. The operations to the left of the decimal point are zero filled less than the specified precision. The result of 1200 is placed in the third position of the result array.


System.out.println(
        client.query( Arr(
                Trunc(Value(1234.5678)),
                Trunc(Value(1234), Value(-2)),
                Trunc(Value(1234.5678), Value(2)),
                Trunc(Value(1234.5678), Value(-2)),
                Trunc(Value(5678.1234), Value(3)),
                Trunc(Value(1234), Value(-3)),
                Trunc(Value(5678.1234), Value(-3))
        )).get());

=> [
  1234.56, 
  1200, 
  1234.56, 
  1200.0, 
  5678.123, 
  1000, 
  5000.0
]

Miscellaneous Functions

Abort


Abort( message )

Abort( message )

Abort( message )

Abort( message )

abort ( message )

abort  message

Abort( message )

Abort( message )

Description

This Abort function terminates the current transaction and augments the returned error with the associated message. Any modifications to data or schema in the aborted transaction will be ignored, even if this modification took place before the abort function was executed.

Parameters

Argument Type Definition and Requirements
message String An abort message.

Returns

An error is returned with the associated abort message.

Examples

The query below is a single transaction with three statements. The first statement creates a class, the second statement adds an instance to the class, and the third statement aborts the transaction. Due to the transaction being terminated by the Abort call, neither the creation of the class nor the addition of the instance will be present in the database.


System.out.println(client.query(
     Arr(
       CreateClass(Obj("name", Value("cars"))),
       Create(
            Class("cars"),
            Obj( "data", Obj( "name", Value("Ford") ) )),
       Abort("Reset Transaction")
     )
).get());

=> ERROR java.util.concurrent.ExecutionException: 
         com.faunadb.client.errors.BadRequestException: transaction aborted: Reset Transaction

Related References

Class


Class( name )

Class( name )

Class( name )

client.query(Class( name )

class_expr( name )

class_ name

client.query(Class( name )

Class( name )

=> 

Description

The Class function returns a valid reference type for the given class name.

Parameters

Argument Type Definition and Requirements
name String The name of a class.

Returns

A reference to a class with the provided name.

Examples

The query below gets a reference to the class named “spells”.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "class": "spells" }'

client.Query(Class("spells"));

System.out.println(client.query(Class(Value("spells"))).get());

result, _ := client.Query(f.Class("spells"))

fmt.Println(result)

client.query(Class("spells"))

client.query(q.class_expr("spells"))

$client.query do
  class_ 'spells'
end

client.query(Class("spells"))

client.query(q.Class("spells"))
  .then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{ "resource": { "@ref": "classes/spells" } }

=> { "@ref": "classes/spells" }

=> ref(id = "spells", class = ref(id = "classes"))

=> {spells 0xc4202cf140 <nil>}

=> { "@ref": "classes/spells" }

=> { "@ref": "classes/spells" }

=> { "@ref": "classes/spells" }

=> { "@ref": "classes/spells" }

=> Ref(id=spells, class=Ref(id=classes))

Related References

Classes


Classes( [database] )

Classes( [database] )

Classes( [database] )

client.query(Classes( [database] )

classes( [database] )

classes [database]

client.query(Classes( [database] )

Classes( [database] )

Description

The Classes function when executed with Paginate returns an array of reference type for all classes in the database specified. If no database is provided, it returns an array of references to all classes in the current database.

Parameters

Argument Type Definition and Requirements
database Ref Optional - The target database.

Returns

A schema set reference

Examples

The query below gets the references to all classes in the current database.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "paginate": { "classes": null } }'

client.Query(Paginate(Classes()));

System.out.println(client.query(Paginate(Classes())).get());

result, _ := client.Query(f.Paginate(f.Classes()))

fmt.Println(result)

client.query(Paginate(Classes()))

client.query(q.paginate(q.classes()))

$client.query do
  paginate classes
end

client.query(Paginate(Classes()))

client.query(q.Paginate(q.Classes()))
  .then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{ "resource": [{ "@ref": "classes/spells" }] }

=> [{ "@ref": "classes/spells" }]

=> [ref(id = "spells", class = ref(id = "classes"))]

=> [{spells 0xc4202cf140 <nil>}]

=> [{ "@ref": "classes/spells" }]

=> [{ "@ref": "classes/spells" }]

=> [{ "@ref": "classes/spells" }]

=> [{ "@ref": "classes/spells" }]

=> [Ref(id=spells, class=Ref(id=classes))]

Related References

Database


Database( name )

Database( name )

Database( name )

Database( name )

database( name )

database name

Database( name )

Database( name )

Description

The Database function returns a valid reference type for a given database name. The Database function only looks up child databases, so finding a database using this function requires you to provide an admin key from the parent database.

Parameters

Argument Type Definition and Requirements
name String The name of a database.

Returns

A reference to a database with the provided name.

Examples

The query below gets a reference to the database named “prydain”.


curl https://db.fauna.com/ \
    -u fnAChGwBacACAEZtRZFDXpyjIvq-sln34m-va4Km: \
    -d '{ "database": "prydain" }'

client.Query(Database("prydain"));

System.out.println(client.query(Database(Value("prydain"))).get());

result, _ := client.Query(f.Database("prydain"))

fmt.Println(result)

client.query(Database("prydain"))

client.query(q.database("prydain"))

$client.query do
  database 'prydain'
end

client.query(Database("prydain"))

client.query(q.Database("prydain"))
  .then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{ "resource": { "@ref": "databases/prydain" } }

=> { "@ref": "databases/prydain" }

=> ref(id = "prydain", class = ref(id = "databases"))

=> {prydain 0xc420316a60 <nil>}

=> { "@ref": "databases/prydain" }

=> { "@ref": "databases/prydain" }

=> { "@ref": "databases/prydain" }

=> { "@ref": "databases/prydain" }

=> Ref(id=prydain, class=Ref(id=databases))

Related References

Databases


Databases( [database] )

Databases( [database] )

Databases( [database] )

Databases( [database] )

databases( [database] )

databases [database]

Databases( [database] )

Databases( [database] )

Description

The Databases function when executed with Paginate returns an array of reference type for sub-databases in the database specified. If no database is provided, it returns an array of references to sub-databases in the current database.

Parameters

Argument Type Definition and Requirements
database Ref Optional - The target database.

Returns

A schema set reference

Examples

The query below gets the references to sub-databases in the current database.


curl https://db.fauna.com/ \
    -u fnAChGwBacACAEZtRZFDXpyjIvq-sln34m-va4Km: \
    -d '{ "paginate": { "databases": null } }'

client.Query(Paginate(Databases()));

System.out.println(client.query(Paginate(Databases())).get());

result, _ := client.Query(f.Paginate(f.Databases()))

fmt.Println(result)

client.query(Paginate(Databases()))

client.query(q.paginate(q.databases()))

$client.query do
  paginate databases
end

client.query(Paginate(Databases()))

client.query(q.Paginate(q.Databases()))
  .then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{ "resource": [{ "@ref": "databases/prydain" }] }

=> [{ "@ref": "databases/prydain" }]

=> [ref(id = "prydain", class = ref(id = "databases"))]

=> [{prydain 0xc420316a60 <nil>}]

=> [{ "@ref": "databases/prydain" }]

=> [{ "@ref": "databases/prydain" }]

=> [{ "@ref": "databases/prydain" }]

=> [{ "@ref": "databases/prydain" }]

=> [Ref(id=prydain, class=Ref(id=databases))]

Related References

Function


Function( name )

Function( name )

Function( name )

Function( name )

function( name )

function name

Function( name )

Function( name )

Description

The Function function returns a reference type for the given function name.

Parameters

Argument Type Definition and Requirements
name String The name of a function.

Returns

A reference to a function with the provided name.

Examples

The query below gets a reference to the function named “increment”.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "function": "increment" }'

client.Query(Function("increment"));

System.out.println(client.query(Function(Value("increment"))).get());

result, _ := client.Query(f.Function("increment"))

fmt.Println(result)

client.query(Function("increment"))

client.query(q.function("increment"))

$client.query do
  function 'increment'
end

client.query(Function("increment"))

client.query(q.Function("increment"))
  .then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{ "resource": { "@ref": "functions/increment" } }

=> { "@ref": "functions/increment" }

=> ref(id = "increment", class = ref(id = "functions"))

=> {increment 0xc4202dd9a0 <nil>}

=> { "@ref": "functions/increment" }

=> { "@ref": "functions/increment" }

=> { "@ref": "functions/increment" }

=> { "@ref": "functions/increment" }

=> Ref(id=increment, class=Ref(id=functions))

Related References

Functions


Functions( [database] )

Functions( [database] )

Functions( [database] )

Functions( [database] )

functions( [database] )

functions [database]

Functions( [database] )

Functions( [database] )

Description

The Functions function when executed with Paginate returns an array of reference type for all user-defined functions in the database specified. If no database is provided, it returns an array of references to all user-defined functions in the current database.

Parameters

Argument Type Definition and Requirements
database Ref Optional - The target database.

Returns

A schema set reference

Examples

The query below gets the references to all user-defined functions in the current database.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "paginate": { "functions": null } }'

client.Query(Paginate(Functions()));

System.out.println(client.query(Paginate(Functions())).get());

result, _ := client.Query(f.Paginate(f.Functions()))

fmt.Println(result)

client.query(Paginate(Functions()))

client.query(q.paginate(q.functions()))

$client.query do
  paginate functions
end

client.query(Paginate(Functions()))

client.query(q.Paginate(q.Functions()))
  .then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{ "resource": [{ "@ref": "functions/increment" }] }

=> [{ "@ref": "functions/increment" }]

=> [ref(id = "increment", class = ref(id = "functions"))]

=> [{increment 0xc4202dd9a0 <nil>}]

=> [{ "@ref": "functions/increment" }]

=> [{ "@ref": "functions/increment" }]

=> [{ "@ref": "functions/increment" }]

=> [{ "@ref": "functions/increment" }]

=> [Ref(id=increment, class=Ref(id=functions))]

Related References

Index


Index( name )

Index( name )

Index( name )

Index( name )

index( name )

index name

Index( name )

Index( name )

Description

The Index function returns a valid reference type for the given index name.

Parameters

Argument Type Definition and Requirements
name String The name of an index.

Returns

A reference to an index with the provided name.

Examples

The query below gets a reference to the index named “spells_by_element”.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "index": "spells_by_element" }'

client.Query(Index("spells_by_element"));

System.out.println(client.query(Index(Value("spells_by_element"))).get());

result, _ := client.Query(f.Index("spells_by_element"))

fmt.Println(result)

client.query(Index("spells_by_element"))

client.query(q.index("spells_by_element"))

$client.query do
  index 'spells_by_element'
end

client.query(Index("spells_by_element"))

client.query(q.Index("spells_by_element"))
  .then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{ "resource": { "@ref": "indexes/spells_by_element" } }

=> { "@ref": "indexes/spells_by_element" }

=> ref(id = "spells_by_element", class = ref(id = "indexes"))

=> {spells_by_element 0xc4202d0fa0 <nil>}

=> { "@ref": "indexes/spells_by_element" }

=> { "@ref": "indexes/spells_by_element" }

=> { "@ref": "indexes/spells_by_element" }

=> { "@ref": "indexes/spells_by_element" }

=> Ref(id=spells_by_element, class=Ref(id=indexes))

Related References

Indexes


Indexes( [database] )

Indexes( [database] )

Indexes( [database] )

Indexes( [database] )

indexes( [database] )

indexes [database]

Indexes( [database] )

Indexes( [database] )

Description

The Indexes function when executed with Paginate returns an array of reference type for all indexes in the database specified. If no database is provided, it returns an array of references to all indexes in the current database.

Parameters

Argument Type Definition and Requirements
database Ref Optional - The target database.

Returns

A schema set reference

Examples

The query below gets the references to all indexes in the current database.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "paginate": { "indexes": null } }'

client.Query(Paginate(Indexes()));

System.out.println(client.query(Paginate(Indexes())).get());

result, _ := client.Query(f.Paginate(f.Indexes()))

fmt.Println(result)

client.query(Paginate(Indexes()))

client.query(q.paginate(q.indexes()))

$client.query do
  paginate indexes
end

client.query(Paginate(Indexes()))

client.query(q.Paginate(q.Indexes()))
  .then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{ "resource": [{ "@ref": "indexes/spells_by_element" }] }

=> [{ "@ref": "indexes/spells_by_element" }]

=> [ref(id = "spells_by_element", class = ref(id = "indexes"))]

=> [{spells_by_element 0xc4202d0fa0 <nil>}]

=> [{ "@ref": "indexes/spells_by_element" }]

=> [{ "@ref": "indexes/spells_by_element" }]

=> [{ "@ref": "indexes/spells_by_element" }]

=> [{ "@ref": "indexes/spells_by_element" }]

=> [Ref(id=spells_by_element, class=Ref(id=indexes))]

Related References

NewId


NewId()

NewId()

NewId()

NewId()

new_id()

new_id

NewId()

NewId()

Description

This NewId function produces a unique number. This number is guaranteed to be unique across the entire cluster and once generated will never be generated a second time. This identifier is suitable for constructing the id part of a reference.

Parameters

None

Returns

A unique number.

Examples

The query below returns a unique number.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "new_id": null }'

client.Query(NewId());

System.out.println(client.query(NewId()).get());

result, _ := client.Query(f.NewId())

fmt.Println(result)

client.query(NewId())

client.query(q.new_id())

$client.query do
  new_id 
end

client.query(NewId())

client.query(q.NewId())
  .then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{ "resource": "181388643266462208" }

=> "181388643266462208"

=> "181388643266462208"

=> 181388643266462208

=> "181388643266462208"

=> "181388643266462208"

=> "181388643266462208"

=> "181388643266462208"

=> 181388643266462208

Related References

Logical Functions

All the logical functions return a boolean type. These functions allow various conditions to be tested. Types have order of precedence. When comparing values of different types, they are ranked in the following order, from greatest to least. For example, a double will be sorted before an integer because of its type.

  1. Nulls
  2. Doubles
  3. Booleans
  4. Dates
  5. Times
  6. Refs
  7. Objects
  8. Arrays
  9. Strings
  10. Integers

And


And(value_1, value_2, ...)

And(value_1, value_2, ...)

And(value_1, value_2, ...)

And(value_1, value_2, ...)

and_expr(value_1, value_2, ...)

and_ value_1, value_2, ...

And(value_1, value_2, ...)

And(value_1, value_2, ...)

Description

The And function computes the conjunction of a list of boolean values, returning “true” if all elements are “true”, and “false” otherwise.

Parameters

Argument Type Definition and Requirements
value Boolean One or more boolean values.

Returns

A boolean value

Examples

The query below returns “false” because the last arguement is “false”.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "and": [ true, true, false ] }'

client.Query(And(true, true, false));

System.out.println(
       client.query(And(Value(true), Value(true), Value(false)))
               .get());

result, _ := client.Query(f.And(true, true, false))

fmt.Println(result)

client.query(And(true, true, false))

client.query(q.and_expr(True, True, False))

$client.query do
  and_ true, true, false
end

client.query(And(true, true, false))

client.query(q.And(true, true, false))
  .then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{ "resource": false }

=> false

=> false

=> false

=> false

=> false

=> false

=> false

=> false

Contains


Contains( path, in )

Contains( path, in )

Contains( path, in )

Contains( path, in )

contains(path, in )

contains path, in

Contains( path, in )

Contains(path, in )

Description

The Contains function returns “true” if the argument passed to “in” contains a value at the specified path, and “false” otherwise.

Parameters

Argument Type Definition and Requirements
path Array of longs or Strings A path to a specified field.
in Any A value of any type.

Returns

A boolean value

Examples

The query below returns “true” because the path “favorites.foods” exists in the document provided to the in argument.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{
          "contains": [ "favorites", "foods" ],
          "in": {
            "object": {
              "favorites": {
                "object": { "foods": [ "crunchings", "munchings", "lunchings" ] }
              }
            }
          }
        }'

client.Query(
  Contains(
    Arr("favorites", "foods"),
    Obj(
      "favorites", Obj("foods", Arr("crunchings", "munchings", "lunchings"))
    )));

System.out.println(
  client.query(
    Contains(
      Arr(Value("favorites"), Value("foods")),
      Obj(
        "favorites", Obj(
          "foods", Arr(
            Value("crunchings"),
            Value("munchings"),
            Value("lunchings")
          )
        )
      )
    )
  )
  .get());

result, _ := client.Query(
    f.Contains(
        f.Arr{"favorites", "foods"},
        f.Obj{
            "favorites": f.Obj{
                "foods": f.Arr{"crunchings", "munchings", "lunchings"},
            },
        },
    ),
)

fmt.Println(result)

client.query(
  Contains(
    Arr("favorites", "foods"),
    Obj(
      "favorites" -> Obj("foods" -> Arr("crunchings", "munchings", "lunchings"))
    )))

client.query(
  q.contains(
    ["favorites", "foods"],
    {
      "favorites": {"foods": ["crunchings", "munchings", "lunchings"]}
    }
  ))

$client.query do
  contains ['favorites', 'foods'],
           favorites: { foods: ['crunchings', 'munchings', 'lunchings'] }
end

client.query(
    Contains(
        path: "favorites", "foods",
        in: Obj(
            "favorites" => Obj(
                "foods" => Arr("crunchings", "munchings", "lunchings")
            )
        )
    )
)

client.query(
  q.Contains(["favorites", "foods"],
    { favorites: { foods: ["crunchings", "munchings", "lunchings"] } }))
.then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{ "resource": true }

=> true

=> true

=> true

=> true

=> true

=> true

=> true

=> true

Related References

Equals


EqualsFn(value_1, value_2, ...)

Equals(value_1, value_2, ...)

Equals(value_1, value_2,...)

Equals(value_1, value_2, ...)

equals(value_1, value_2, ...)

equals value_1, value_2, ...

Equals(value_1, value_2, ...)

Equals(value_1, value_2, ...)

Description

The Equals function tests equivalence between a list of values.

Parameters

Argument Type Definition and Requirements
value Any A single boolean value.

Returns

A boolean value

Examples

The query below returns “true” because “fire” is equivalent to “fire”.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "equals": [ "fire", "fire" ] }'

client.Query(EqualsFn("fire", "fire"));

System.out.println(client.query(Equals(Value("fire"),Value("fire"))).get());

result, _ := client.Query(f.Equals("fire", "fire"))

fmt.Println(result)

client.query(Equals("fire", "fire"))

client.query(q.equals("fire", "fire"))

$client.query do
  equals 'fire', 'fire'
end

client.query(Equals("fire", "fire"))

client.query(q.Equals("fire", "fire"))
  .then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{ "resource": true }

=> true

=> true

=> true

=> true

=> true

=> true

=> true

=> true

Related References

Exists


Exists( ref, [ts] )

Exists( ref, [ts] )

Exists( ref, [ts] )

Exists( ref, [ts] )

exists( ref, [ts]

exists  ref, [ts] )

Exists( ref, [ts] )

Exists( ref, [ts] )

Description

The Exists function returns boolean “true” if the provided ref exists at the specified timestamp (in the case of an instance), or is non-empty (in the case of a set), and “false” otherwise.

Parameters

Argument Type Definition and Requirements
ref Reference The reference identifier within the database uniquely identifying an instance.
ts Long Optional - Existence of the ref is checked at the given timestamp (number of UNIX microseconds or time value). Defaults to the current time.

Returns

A boolean value

Examples

The query below checks for the existence of a ref pointing at an instance in the spells class at value 181388642046968320L. Since this ref is present at the current time, “true” is returned.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "exists": { "@ref": "classes/spells/181388642046968320" } }'

client.Query(Exists(Ref("classes/spells/181388642046968320")));

System.out.println(
       client.query(
               Exists(Ref(
                       Class("spells"),
                       Value(181388642046968320L)
                       )
               )
       ).get()); 

result, _ := client.Query(
    f.Exists(f.RefClass(f.Class("spells"), "181388642046968320")),
)

fmt.Println(result)

client.query(Exists(Ref("classes/spells/181388642046968320")))

client.query(q.exists(Ref("classes/spells/181388642046968320")))

$client.query do
  exists ref('classes/spells/181388642046968320')
end

client.query(
    Exists(Ref("classes/spells/181388642046968320"))
)

client.query(q.Exists(q.Ref(q.Class("spells"), 181388642046968320)))
  .then((ret) => console.log(ret));

=> HTTP/1.1 200 OK
{ "resource": true }

=> true

=> true

=> true

=> true

=> true

=> true

=> true

=> true

Related References

Gt


GT(value_1, value_2, ... )

GT(value_1, value_2, ... )

GT(value_1, value_2, ... )

GT(value_1, value_2, ... )

gt(value_1, value_2, ... )

gt value_1, value_2, ...

GT(value_1, value_2, ... )

GT(value_1, value_2, ... )

Description

The Gt function returns “true” if each specified value is greater than the ones following it, and “false” otherwise. The function takes one or more arguments; it always returns “true” if it has a single argument.

Parameters

Argument Type Definition and Requirements
value Any A value to be compared.

Returns

A boolean value

Examples

The query below returns “true” because the value 3 is greater than the value 2, and the value 2 is greater than the value 1.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "gt": [ 3, 2, 1 ] }'

client.Query(GT(3, 2, 1));

System.out.println(
        client.query(GT(Value(3), Value(2), Value(1)))
        .get());

result, _ := client.Query(f.GT(3, 2, 1))

fmt.Println(result)

client.query(GT(3, 2, 1))

client.query(q.gt(3, 2, 1))

$client.query do
  gt 3, 2, 1
end

client.query(GT(3, 2, 1))

client.query(q.GT(3, 2, 1))
  .then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{ "resource": true }

=> true

=> true

=> true

=> true

=> true

=> true

=> true

=> true

Related References

Gte


GTE(value_1, value_2, ... )

GTE(value_1, value_2, ... )

GTE(value_1, value_2, ... )

GTE(value_1, value_2, ... )

gte(value_1, value_2, ... )

gte value_1, value_2, ...

GTE(value_1, value_2, ... )

GTE(value_1, value_2, ... )

Description

The Gte function returns “true” if each specified value is greater than or equal to the ones following it, and “false” otherwise. The function takes one or more arguments; it always returns “true” if it has a single argument.

Parameters

Argument Type Definition and Requirements
value Any A value to be compared.

Returns

A boolean value

Examples

The query below returns “true” because the value 3 is greater than or equal to the value 2, and the value 2 is greater than or equal to the second value 2.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "gte": [ 3, 2, 2 ] }'

client.Query(GTE(3, 2, 2));

System.out.println(
    client.query(GTE(Value(3), Value(2), Value(2)))
    .get());

result, _ := client.Query(f.GTE(3, 2, 2))

fmt.Println(result)

client.query(GTE(3, 2, 2))

client.query(q.gte(3, 2, 2))

$client.query do
  gte 3, 2, 2
end

client.query(GTE(3, 2, 2))

client.query(q.GTE(3, 2, 2))
  .then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{ "resource": true }

=> true

=> true

=> true

=> true

=> true

=> true

=> true

=> true

Related References

Lt


LT(value_1, value_2, ...)

LT(value_1, value_2, ...)

LT(value_1, value_2, ...)

LT(value_1, value_2, ...)

lt(value_1, value_2, ...)

lt value_1, value_2, ...

LT(value_1, value_2, ...)

LT(value_1, value_2, ...)

Description

The Lt function returns “true” if each specified value is less than the ones following it, and “false” otherwise. The function takes one or more arguments; it always returns “true” if it has a single argument.

Parameters

Argument Type Definition and Requirements
value Any A value to be compared.

Returns

A boolean value

Examples

The query below returns “true” because the value 1 is less than the value 2, and the value 2 is less than the value 3.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "lt": [ 1, 2, 3 ] }'

client.Query(LT(1, 2, 3));

System.out.println(
    client.query(LT(Value(1), Value(2), Value(3)))
    .get());

result, _ := client.Query(f.LT(1, 2, 3))

fmt.Println(result)

client.query(LT(1, 2, 3))

client.query(q.lt(1, 2, 3))

$client.query do
  lt 1, 2, 3
end

client.query(LT(1, 2, 3))

client.query(q.LT(1, 2, 3))
  .then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{ "resource": true }

=> true

=> true

=> true

=> true

=> true

=> true

=> true

=> true

Related References

Lte


LT(value_1, value_2, ...)

LT(value_1, value_2, ...)

LT(value_1, value_2, ...)

LT(value_1, value_2, ...)

lt(value_1, value_2, ...)

lt value_1, value_2, ...

LT(value_1, value_2, ...)

LT(value_1, value_2, ...)

Description

The Lte function returns “true” if each specified value is less than or equal to the ones following it, and “false” otherwise. The function takes one or more arguments; it always returns “true” if it has a single argument.

Parameters

Argument Type Definition and Requirements
value Any A value to be compared.

Returns

A boolean value

Examples

The query below returns “true” because the value 1 is less than or equal to the value 2, and the value 2 is less than or equal to the second value 2.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "lte": [ 1, 2, 2 ] }'

client.Query(LTE(1, 2, 2));

System.out.println(
    client.query(LTE(Value(1), Value(2), Value(2)))
    .get());

result, _ := client.Query(f.LTE(1, 2, 2))

fmt.Println(result)

client.query(LTE(1, 2, 2))

client.query(q.lte(1, 2, 2))

$client.query do
  lte 1, 2, 2
end

client.query(LTE(1, 2, 2))

client.query(q.LTE(1, 2, 2))
  .then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{ "resource": true }

=> true

=> true

=> true

=> true

=> true

=> true

=> true

=> true

Related References

Not


Not(value)

Not(value)

Not(value)

Not(value)

not_expr(value)

not_ value

Not(value)

Not(value)

Description

The Not function computes the negation of a boolean value, returning “true” if its argument is “false”, or “false” if its argument is “true”.

Parameters

Argument Type Definition and Requirements
value Boolean A single boolean value.

Returns

A boolean value

Examples

The query below returns “false” because an argument of “true” is provided.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "not": true }'

client.Query(Not(true));

System.out.println(client.query(Not(Value(true))).get());

result, _ := client.Query(f.Not(true))

fmt.Println(result)

client.query(Not(true))

client.query(q.not_expr(True))

$client.query do
  not_ true
end

client.query(Not(true))

client.query(q.Not(true))
  .then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{ "resource": false }

=> false

=> false

=> false

=> false

=> false

=> false

=> false

=> false

Related References

Or


Or(value_1, value_2, ...)

Or(value_1, value_2, ...)

Or(value_1, value_2, ...)

Or(value_1, value_2, ... )

or_expr(value_1, value_2, ...)

or_ value_1, value_2, ...

Or(value_1, value_2, ... )

Or(value_1, value_2, ...)

Description

The Or function operates on one or more values and returns true if at least one of the values is true.

Parameters

Argument Type Definition and Requirements
value Any A value to be compared.

Returns

A boolean value

Examples

The query below returns “true” because at least one of the provided values is “true”.


curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "or": [ true, true, false ] }'

client.Query(Or(true, true, false));

System.out.println(
        client.query(Or(Value(true), Value(true), Value(false)))
        .get());

result, _ := client.Query(f.Or(true, true, false))

fmt.Println(result)

client.query(Or(true, true, false))

client.query(q.or_expr(True, True, False))

$client.query do
  or_ true, true, false
end

client.query(Or(true, true, false))

client.query(q.Or(true, true, false))
  .then((ret) => console.log(ret))

=> HTTP/1.1 200 OK
{ "resource": true }

=> true

=> true

=> true

=> true

=> true

=> true

=> true

=> true

Related References