01 Documentation

Languages:

Introduction

The FaunaDB query language is the primary interface for interacting with FaunaDB Cloud or a FaunaDB Enterprise 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

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

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

import faunadb.FaunaClient
import faunadb.query._

require 'fauna'

using FaunaDB.Client;
using FaunaDB.Types;

using static FaunaDB.Query.Language;

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

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

import FaunaDB

Values

Literals

Booleans, Integers, Decimals, Strings, and Null JSON literals all evaluate to themselves:


true, false   // Booleans
1, 2          // Integers
3.4, 1.2e10   // Decimals
"a", "b"      // Strings
null          // Null

Arrays

Arrays evaluate to their contents:


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

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

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

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

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

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

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

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

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

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" ]

Objects

Because regular JSON objects represent function calls, object values must be constructed using object:


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

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

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

client.query(Obj("name" -> "Hen Wen", "age" -> 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)})

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

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

HTTP/1.1 200 OK
{ "resource": { "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 }

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

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

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

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

Special Types

FaunaDB supports some types beyond those native to JSON. Special types 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 @.

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


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

client.query(Ref("classes/spells/104979509692858368"));

client.query(Ref("classes/spells/104979509692858368"));

client.query(Ref("classes/spells/104979509692858368"))

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

client.Query(Ref("classes/spells/104979509692858368"));

client.query(Ref("classes/spells/104979509692858368"))

client.Query(f.Ref("classes/spells/104979509692858368"))

client.query(Ref("classes/spells/104979509692858368"))

HTTP/1.1 200 OK
{ "resource": { "@ref": "classes/spells/104979509692858368" } }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@set denotes a set identifier.


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

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

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

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

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

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

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

client.Query(
    f.MatchTerm(f.Ref("indexes/spells_by_element"), "fire"),
)

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

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": "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"
  }
}

=> {
  "@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"
  }
}

@ts denotes a time in UTC. Times 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 kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE: \
    -d '{ "time": "1970-01-01T00:00:00Z" }'

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


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

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

client.query(new Uint8Array([0x1, 0x2, 0x3]));

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

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

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

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

client.Query(BytesV{0x1, 0x2, 0x3})

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

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

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

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

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

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

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

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

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

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

@obj denotes a literal object, escaping type tags. Clients should not normally need to use this escape form. It is only required and will be returned by FaunaDB if an object is constructed with a reserved key.


curl https://db.fauna.com/ \
    -u kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE: \
    -d '{ "@obj": { "@name": "Hen Wen", "age": 110 } }'

Obj("@obj", Obj("@name", Value("Hen Wen"), "age", Value(110)));

{ "@obj": { "@name": "Hen Wen", "age": 110 } }

Obj("@obj" -> Obj("@name" -> "Hen Wen", "age" -> 110))

{ '@obj' => { '@name' => 'Hen Wen', 'age' => 110 } }

Obj("@obj", Obj("@name", "Hen Wen", "age", 110));

{"@obj": {"@name": "Hen Wen", "age": 110}}

f.Obj{"@obj": f.Obj{"@name": "Hen Wen", "age": 110}}

Obj("@obj" -> Obj("@name" -> "Hen Wen", "age" -> 110))

Pages

The paginate function returns a Page object that groups together a page of results and cursors for retrieving pages before or after the current page. Pages are collections and can be passed directly to some functions–such as map or filter. Transformations are applied to the Page’s data array; cursors are passed through.

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.

Depending upon the arguments to paginate, returned Cursors may be any one of:

  • An Event object.
  • One or more covered values.
  • The cursor provided to paginate.

Events

Events are objects that are returned when paginating through an instance or set’s historical timeline. See the paginate function for more.

Field Type
ts Integer The microsecond UNIX timestamp at which the event occurred.
action String Either “create” or “delete”.
resource Ref The ref of the affected instance.

Basic Forms

let(bindings, in)

let binds values to one or more variables. Variable values cannot refer to other variables defined in the same let expression. Variables are lexically scoped to the expression passed via in.


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

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

client.query(q.Let({ x: 1, y: 2 }, q.Var("x")));

client.query(
  Let {
    val x = 1
    val y = 2
    x
  })

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

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

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

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

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

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

=> 1

=> 1

=> 1

=> 1

=> 1

=> 1

=> 1

=> 1

var(varname)

A var expression refers to the value of a variable varname in the current lexical scope. Referring to a variable that is not in scope results in an “unbound variable” error.


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

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

client.query(q.Let({ x: 1, y: 2 }, q.Var("x")));

client.query(
  Let {
    val x = 1
    val y = 2
    x
  })

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

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

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

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

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

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

=> 1

=> 1

=> 1

=> 1

=> 1

=> 1

=> 1

=> 1

if(cond, true_expr, false_expr)

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


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

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

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

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

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

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

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

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

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

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

=> "was true"

=> "was true"

=> "was true"

=> "was true"

=> "was true"

=> "was true"

=> "was true"

=> "was true"

do(expr_1, expr_2, ..., return_expr)

do sequentially evaluates its arguments, and returns the last expression. If no expressions are provided, do returns an error.


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(Value("magical_creatures")), Value(1)),
      Obj("data", Obj("name", Value("Hen Wen")))),
    Get(Ref(Class(Value("magical_creatures")), Value(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))));

client.query(
  Do(
    Create(
      Ref(Class("magical_creatures"), 1),
      Obj("data" -> Obj("name" -> "Hen Wen"))),
    Get(Ref(Class("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(
      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(
    f.Do(
        f.Create(
            f.Ref(f.Class("magical_creatures"), 1),
            f.Obj{"data": f.Obj{"name": "Hen Wen"}},
        ),
        f.Get(f.Ref(f.Class("magical_creatures"), 1)),
    ),
)

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

quote(expr) (deprecated)

quote returns the unevaluted form of expr.


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

// Not applicable;

// Not applicable

// Not applicable

# Not applicable

// Not applicable

# Not applicable

// Not applicable

// Not applicable

HTTP/1.1 200 OK
{
  "resource": { "name": "Hen Wen", "age": { "add": [ 100, 10 ] } }
}

=> { "name": "Hen Wen", "age": { "add": [ 100, 10 ] } }

=> { "name": "Hen Wen", "age": { "add": [ 100, 10 ] } }

=> { "name": "Hen Wen", "age": { "add": [ 100, 10 ] } }

=> { "name": "Hen Wen", "age": { "add": [ 100, 10 ] } }

=> { "name": "Hen Wen", "age": { "add": [ 100, 10 ] } }

=> { "name": "Hen Wen", "age": { "add": [ 100, 10 ] } }

=> { "name": "Hen Wen", "age": { "add": [ 100, 10 ] } }

=> { "name": "Hen Wen", "age": { "add": [ 100, 10 ] } }

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

// Not applicable;

// Not applicable

// Not applicable

# Not applicable

// Not applicable

# Not applicable

// Not applicable

// Not applicable

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

=> [ 1, 2, { "concat": [ "Hen ", "Wen" ] } ]

=> [ 1, 2, { "concat": [ "Hen ", "Wen" ] } ]

=> [ 1, 2, { "concat": [ "Hen ", "Wen" ] } ]

=> [ 1, 2, { "concat": [ "Hen ", "Wen" ] } ]

=> [ 1, 2, { "concat": [ "Hen ", "Wen" ] } ]

=> [ 1, 2, { "concat": [ "Hen ", "Wen" ] } ]

=> [ 1, 2, { "concat": [ "Hen ", "Wen" ] } ]

=> [ 1, 2, { "concat": [ "Hen ", "Wen" ] } ]

lambda(params, expr)

lambda creates an anonymous function that binds one or more variables in the expression at expr.

The lambda form is only permitted as a direct argument to a form which applies it. It cannot be bound to a variable.


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

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

client.query(
  q.Map(
    ["Hen "],
    function(name) {
      return q.Concat([name, "Wen"]);
    }));

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

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

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

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

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

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

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

=> [ "Hen Wen" ]

=> [ "Hen Wen" ]

=> [ "Hen Wen" ]

=> [ "Hen Wen" ]

=> [ "Hen Wen" ]

=> [ "Hen Wen" ]

=> [ "Hen Wen" ]

=> [ "Hen Wen" ]

params can be a single parameter or an array of parameters. Arguments are bound to the parameter names in the body of the lambda.

Lambdas that define multiple parameters are useful in contexts where the provided argument is expected to be an array (such as mapping over pages of a set). In this context, the passed array’s elements are bound rather than the array itself. The array argument must have the same number of elements as the lambda has expected arguments.


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

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

client.query(
  q.Map(
    [["Hen", "Wen"]],
    function(f, l) {
      return q.Concat([f, l], " ");
    }));

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

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

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

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

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(" "),
            ),
        ),
    ),
)

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

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

=> [ "Hen Wen" ]

=> [ "Hen Wen" ]

=> [ "Hen Wen" ]

=> [ "Hen Wen" ]

=> [ "Hen Wen" ]

=> [ "Hen Wen" ]

=> [ "Hen Wen" ]

=> [ "Hen Wen" ]

If an element of an array is not required, it may be discarded with the label _:


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

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

client.query(
  q.Map([["Hen", "Wen"]], function(f, _) { return f; }));

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

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

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

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

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

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

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

=> [ "Hen" ]

=> [ "Hen" ]

=> [ "Hen" ]

=> [ "Hen" ]

=> [ "Hen" ]

=> [ "Hen" ]

=> [ "Hen" ]

=> [ "Hen" ]

call(function_ref, arguments)

call calls the user defined function identified by function_ref with the provided arguments.


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

// Not available in this language yet.

// Not available in this language yet.

// Not available in this language yet.

# Not available in this language yet.

// Not available in this language yet.

# Not available in this language yet.

// Not available in this language yet.

// Not available in this language yet.

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

=> 3

=> 3

=> 3

=> 3

=> 3

=> 3

=> 3

=> 3

at(timestamp, expr)

at executes reads in the associated expr using timestamp as the valid time. Writes will still use the current transaction time as returned by { "time": "now" }.


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

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(
  At(Time("1970-01-01T00:00:00Z"), Paginate(Ref("classes"))))

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

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(
    f.At(
        f.Time("1970-01-01T00:00:00Z"),
        f.Paginate(f.Ref("classes")),
    ),
)

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

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

=> { "data": [ ] }

=> { "data": [ ] }

=> { "data": [ ] }

=> { "data": [ ] }

=> { "data": [ ] }

=> { "data": [ ] }

=> { "data": [ ] }

=> { "data": [ ] }

Collections

Functions that operate on collections. In general, a collection in FaunaDB is either an Array or Page.

map(lambda, collection)

map applies lambda to each member of the Array or Page collection, and returns the results of each application in a new collection of the same type. If a Page is passed, its cursor is preserved in the result.

map applies the lambda concurrently to each element of the collection collection. Side-effects, such as writes, do not affect evaluation of other lambda applications. The order of possible refs being generated within the lambda are non-deterministic.


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

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

client.query(
  q.Map([1, 2, 3], function(x) { return q.Add(x, 1); }));

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

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

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

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

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

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

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 ]

foreach(lambda, collection)

foreach applies lambda to each member of the Array or Page collection. The original collection is returned.

foreach applies the lambda concurrently to each element of the collection. Side-effects, such as writes, do not affect evaluation of other lambda applications. The order of possible refs being generated within the lambda are non-deterministic.


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

client.query(
  Foreach(
    Paginate(
        Match(Index(Value("spells_by_element")), Value("fire"))),
    Lambda(
      Value("spell"),
      Update(
        Var("spell"),
        Obj(
          "data", Obj(
            "spellbook", Ref("classes/spellbooks/104979509693618791")
          )
        )))));

client.query(
  q.Foreach(
    q.Paginate(q.Match(q.Index("spells_by_element"), "fire")),
    function(spell) {
      return q.Update(
        spell,
        {
          data: { spellbook: Ref("classes/spellbooks/104979509693618791") }
        });
    }));

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

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

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

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

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.Ref("classes/spellbooks/104979509693618791"),
                    },
                },
            ),
        ),
    ),
)

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/104979509693618791")
                    )
                )
            )
        }
    )
)

HTTP/1.1 200 OK
{
  "resource": {
    "data": [
      { "@ref": "classes/spells/104979509694379214" },
      { "@ref": "classes/spells/104979509692858368" }
    ]
  }
}

=> {
  "data": [
    { "@ref": "classes/spells/104979509694379214" },
    { "@ref": "classes/spells/104979509692858368" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/104979509694379214" },
    { "@ref": "classes/spells/104979509692858368" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/104979509694379214" },
    { "@ref": "classes/spells/104979509692858368" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/104979509694379214" },
    { "@ref": "classes/spells/104979509692858368" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/104979509694379214" },
    { "@ref": "classes/spells/104979509692858368" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/104979509694379214" },
    { "@ref": "classes/spells/104979509692858368" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/104979509694379214" },
    { "@ref": "classes/spells/104979509692858368" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/104979509694379214" },
    { "@ref": "classes/spells/104979509692858368" }
  ]
}

filter(lambda, collection)

filter applies lambda to each member of the Array or Page 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 cursor is preserved in the result.


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

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

client.query(
  q.Filter(
    [1, 2, 3],
    function(i) {
      return q.Equals(0, q.Modulo(i, 2));
    }));

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

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

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

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

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

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

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

=> [ 2 ]

=> [ 2 ]

=> [ 2 ]

=> [ 2 ]

=> [ 2 ]

=> [ 2 ]

=> [ 2 ]

=> [ 2 ]

take(num, collection)

take returns a new Array or Page that contains num elements from the head of the Array or Page collection. If num is zero or negative, the resulting collection is empty.

When applied to a 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.

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

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

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

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

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

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

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

client.Query(f.Take(2, f.Arr{1, 2, 3}))

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

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

=> [ 1, 2 ]

=> [ 1, 2 ]

=> [ 1, 2 ]

=> [ 1, 2 ]

=> [ 1, 2 ]

=> [ 1, 2 ]

=> [ 1, 2 ]

=> [ 1, 2 ]

drop(num, collection)

drop returns a new Array or Page that contains the remaining elements, after num have been removed from the head of the Array or Page collection. If num is zero or negative, elements of the collection are returned unmodified.

When applied to a 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.

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

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

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

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

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

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

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

client.Query(f.Drop(2, f.Arr{1, 2, 3}))

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

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

=> [ 3 ]

=> [ 3 ]

=> [ 3 ]

=> [ 3 ]

=> [ 3 ]

=> [ 3 ]

=> [ 3 ]

=> [ 3 ]

prepend(elems, array)

prepend returns a new Array that is the result of prepending elems onto the Array array.


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

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

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

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

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

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

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

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

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

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 ]

append(elems, array)

append returns a new Array that is the result of appending elems onto the Array array.


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

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

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

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

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

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

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

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

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

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 ]

Read Functions

get(ref, [ts])

get retrieves the instance identified by ref. 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.

Parameters
ts Integer or time value optional Return the instance at the specified point in time (number of UNIX microseconds or time value).

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

client.query(Get(Ref("classes/spells/104979509694379214")));

client.query(q.Get(Ref("classes/spells/104979509694379214")));

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

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

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

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

client.Query(f.Get(f.Ref("classes/spells/104979509694379214")))

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

HTTP/1.1 200 OK
{
  "resource": {
    "ref": { "@ref": "classes/spells/104979509694379214" },
    "class": { "@ref": "classes/spells" },
    "ts": 1436375112374190,
    "data": {
      "name": "Fire Beak",
      "element": [ "air", "fire" ],
      "spellbook": { "@ref": "classes/spellbooks/104979509693618791" }
    }
  }
}

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

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

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

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

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

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

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

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

FaunaDB does not provide a multi-get function, but multiple calls to get may be grouped and returned:


curl https://db.fauna.com/ \
    -u kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE: \
    -d '[
          { "get": { "@ref": "classes/spells/104979509694379214" } },
          { "get": { "@ref": "classes/spells/104979509692858368" } },
          { "get": { "@ref": "classes/spells/104979509695139637" } }
        ]'

client.query(
  Arr(
    Get(Ref("classes/spells/104979509694379214")),
    Get(Ref("classes/spells/104979509692858368")),
    Get(Ref("classes/spells/104979509695139637"))
  ));

client.query(
  [
    q.Get(Ref("classes/spells/104979509694379214")),
    q.Get(Ref("classes/spells/104979509692858368")),
    q.Get(Ref("classes/spells/104979509695139637"))
  ]);

client.query(
  Arr(
    Get(Ref("classes/spells/104979509694379214")),
    Get(Ref("classes/spells/104979509692858368")),
    Get(Ref("classes/spells/104979509695139637"))
  ))

$client.query do
  [
    get(ref('classes/spells/104979509694379214')),
    get(ref('classes/spells/104979509692858368')),
    get(ref('classes/spells/104979509695139637'))
  ]
end

client.Query(
  Arr(
    Get(Ref("classes/spells/104979509694379214")),
    Get(Ref("classes/spells/104979509692858368")),
    Get(Ref("classes/spells/104979509695139637"))
  ));

client.query(
  [
    q.get(Ref("classes/spells/104979509694379214")),
    q.get(Ref("classes/spells/104979509692858368")),
    q.get(Ref("classes/spells/104979509695139637"))
  ])

client.Query(
    f.Arr{
        f.Get(f.Ref("classes/spells/104979509694379214")),
        f.Get(f.Ref("classes/spells/104979509692858368")),
        f.Get(f.Ref("classes/spells/104979509695139637")),
    },
)

client.query(
    Arr(
        Get(Ref("classes/spells/104979509694379214")),
        Get(Ref("classes/spells/104979509692858368")),
        Get(Ref("classes/spells/104979509695139637"))
    )
)

HTTP/1.1 200 OK
{
  "resource": [
    {
      "ref": { "@ref": "classes/spells/104979509694379214" },
      "class": { "@ref": "classes/spells" },
      "ts": 1436375112374190,
      "data": {
        "name": "Fire Beak",
        "element": [ "air", "fire" ],
        "spellbook": { "@ref": "classes/spellbooks/104979509693618791" }
      }
    },
    {
      "ref": { "@ref": "classes/spells/104979509692858368" },
      "class": { "@ref": "classes/spells" },
      "ts": 1436375112374190,
      "data": {
        "name": "Water Dragon's Claw",
        "element": [ "water", "fire" ],
        "spellbook": { "@ref": "classes/spellbooks/104979509693618791" }
      }
    },
    {
      "ref": { "@ref": "classes/spells/104979509695139637" },
      "class": { "@ref": "classes/spells" },
      "ts": 1436375112316028,
      "data": {
        "name": "Hippo's Wallow",
        "element": [ "water", "earth" ]
      }
    }
  ]
}

=> [
  {
    "ref": { "@ref": "classes/spells/104979509694379214" },
    "class": { "@ref": "classes/spells" },
    "ts": 1436375112374190,
    "data": {
      "name": "Fire Beak",
      "element": [ "air", "fire" ],
      "spellbook": { "@ref": "classes/spellbooks/104979509693618791" }
    }
  },
  {
    "ref": { "@ref": "classes/spells/104979509692858368" },
    "class": { "@ref": "classes/spells" },
    "ts": 1436375112374190,
    "data": {
      "name": "Water Dragon's Claw",
      "element": [ "water", "fire" ],
      "spellbook": { "@ref": "classes/spellbooks/104979509693618791" }
    }
  },
  {
    "ref": { "@ref": "classes/spells/104979509695139637" },
    "class": { "@ref": "classes/spells" },
    "ts": 1436375112316028,
    "data": {
      "name": "Hippo's Wallow",
      "element": [ "water", "earth" ]
    }
  }
]

=> [
  {
    "ref": { "@ref": "classes/spells/104979509694379214" },
    "class": { "@ref": "classes/spells" },
    "ts": 1436375112374190,
    "data": {
      "name": "Fire Beak",
      "element": [ "air", "fire" ],
      "spellbook": { "@ref": "classes/spellbooks/104979509693618791" }
    }
  },
  {
    "ref": { "@ref": "classes/spells/104979509692858368" },
    "class": { "@ref": "classes/spells" },
    "ts": 1436375112374190,
    "data": {
      "name": "Water Dragon's Claw",
      "element": [ "water", "fire" ],
      "spellbook": { "@ref": "classes/spellbooks/104979509693618791" }
    }
  },
  {
    "ref": { "@ref": "classes/spells/104979509695139637" },
    "class": { "@ref": "classes/spells" },
    "ts": 1436375112316028,
    "data": {
      "name": "Hippo's Wallow",
      "element": [ "water", "earth" ]
    }
  }
]

=> [
  {
    "ref": { "@ref": "classes/spells/104979509694379214" },
    "class": { "@ref": "classes/spells" },
    "ts": 1436375112374190,
    "data": {
      "name": "Fire Beak",
      "element": [ "air", "fire" ],
      "spellbook": { "@ref": "classes/spellbooks/104979509693618791" }
    }
  },
  {
    "ref": { "@ref": "classes/spells/104979509692858368" },
    "class": { "@ref": "classes/spells" },
    "ts": 1436375112374190,
    "data": {
      "name": "Water Dragon's Claw",
      "element": [ "water", "fire" ],
      "spellbook": { "@ref": "classes/spellbooks/104979509693618791" }
    }
  },
  {
    "ref": { "@ref": "classes/spells/104979509695139637" },
    "class": { "@ref": "classes/spells" },
    "ts": 1436375112316028,
    "data": {
      "name": "Hippo's Wallow",
      "element": [ "water", "earth" ]
    }
  }
]

=> [
  {
    "ref": { "@ref": "classes/spells/104979509694379214" },
    "class": { "@ref": "classes/spells" },
    "ts": 1436375112374190,
    "data": {
      "name": "Fire Beak",
      "element": [ "air", "fire" ],
      "spellbook": { "@ref": "classes/spellbooks/104979509693618791" }
    }
  },
  {
    "ref": { "@ref": "classes/spells/104979509692858368" },
    "class": { "@ref": "classes/spells" },
    "ts": 1436375112374190,
    "data": {
      "name": "Water Dragon's Claw",
      "element": [ "water", "fire" ],
      "spellbook": { "@ref": "classes/spellbooks/104979509693618791" }
    }
  },
  {
    "ref": { "@ref": "classes/spells/104979509695139637" },
    "class": { "@ref": "classes/spells" },
    "ts": 1436375112316028,
    "data": {
      "name": "Hippo's Wallow",
      "element": [ "water", "earth" ]
    }
  }
]

=> [
  {
    "ref": { "@ref": "classes/spells/104979509694379214" },
    "class": { "@ref": "classes/spells" },
    "ts": 1436375112374190,
    "data": {
      "name": "Fire Beak",
      "element": [ "air", "fire" ],
      "spellbook": { "@ref": "classes/spellbooks/104979509693618791" }
    }
  },
  {
    "ref": { "@ref": "classes/spells/104979509692858368" },
    "class": { "@ref": "classes/spells" },
    "ts": 1436375112374190,
    "data": {
      "name": "Water Dragon's Claw",
      "element": [ "water", "fire" ],
      "spellbook": { "@ref": "classes/spellbooks/104979509693618791" }
    }
  },
  {
    "ref": { "@ref": "classes/spells/104979509695139637" },
    "class": { "@ref": "classes/spells" },
    "ts": 1436375112316028,
    "data": {
      "name": "Hippo's Wallow",
      "element": [ "water", "earth" ]
    }
  }
]

=> [
  {
    "ref": { "@ref": "classes/spells/104979509694379214" },
    "class": { "@ref": "classes/spells" },
    "ts": 1436375112374190,
    "data": {
      "name": "Fire Beak",
      "element": [ "air", "fire" ],
      "spellbook": { "@ref": "classes/spellbooks/104979509693618791" }
    }
  },
  {
    "ref": { "@ref": "classes/spells/104979509692858368" },
    "class": { "@ref": "classes/spells" },
    "ts": 1436375112374190,
    "data": {
      "name": "Water Dragon's Claw",
      "element": [ "water", "fire" ],
      "spellbook": { "@ref": "classes/spellbooks/104979509693618791" }
    }
  },
  {
    "ref": { "@ref": "classes/spells/104979509695139637" },
    "class": { "@ref": "classes/spells" },
    "ts": 1436375112316028,
    "data": {
      "name": "Hippo's Wallow",
      "element": [ "water", "earth" ]
    }
  }
]

=> [
  {
    "ref": { "@ref": "classes/spells/104979509694379214" },
    "class": { "@ref": "classes/spells" },
    "ts": 1436375112374190,
    "data": {
      "name": "Fire Beak",
      "element": [ "air", "fire" ],
      "spellbook": { "@ref": "classes/spellbooks/104979509693618791" }
    }
  },
  {
    "ref": { "@ref": "classes/spells/104979509692858368" },
    "class": { "@ref": "classes/spells" },
    "ts": 1436375112374190,
    "data": {
      "name": "Water Dragon's Claw",
      "element": [ "water", "fire" ],
      "spellbook": { "@ref": "classes/spellbooks/104979509693618791" }
    }
  },
  {
    "ref": { "@ref": "classes/spells/104979509695139637" },
    "class": { "@ref": "classes/spells" },
    "ts": 1436375112316028,
    "data": {
      "name": "Hippo's Wallow",
      "element": [ "water", "earth" ]
    }
  }
]

=> [
  {
    "ref": { "@ref": "classes/spells/104979509694379214" },
    "class": { "@ref": "classes/spells" },
    "ts": 1436375112374190,
    "data": {
      "name": "Fire Beak",
      "element": [ "air", "fire" ],
      "spellbook": { "@ref": "classes/spellbooks/104979509693618791" }
    }
  },
  {
    "ref": { "@ref": "classes/spells/104979509692858368" },
    "class": { "@ref": "classes/spells" },
    "ts": 1436375112374190,
    "data": {
      "name": "Water Dragon's Claw",
      "element": [ "water", "fire" ],
      "spellbook": { "@ref": "classes/spellbooks/104979509693618791" }
    }
  },
  {
    "ref": { "@ref": "classes/spells/104979509695139637" },
    "class": { "@ref": "classes/spells" },
    "ts": 1436375112316028,
    "data": {
      "name": "Hippo's Wallow",
      "element": [ "water", "earth" ]
    }
  }
]

paginate(set, [params])

paginate retrieves a page from the set identified by set. A valid set is any set identifier or instance ref. Instance refs represent singleton sets of themselves.

Parameters
ts Integer or time value optional Return the 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 default 16 Maximum number of results to return.
events Boolean default false If true, return a page from the event history of the set.
sources Boolean default false If true, include the source sets along with each element.

The type of pagination cursor depends on whether or not a page from a set or events timeline is requested. 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.

Simple page get:


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

client.query(
  Paginate(
      Union(
        Match(Index(Value("spells_by_element")), Value("fire")),
        Match(Index(Value("spells_by_element")), Value("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(
  Paginate(
    Union(
      Match(Index("spells_by_element"), "fire"),
      Match(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("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(
    f.Paginate(
        f.Union(
            f.MatchTerm(f.Index("spells_by_element"), "fire"),
            f.MatchTerm(f.Index("spells_by_element"), "water"),
        ),
    ),
)

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

HTTP/1.1 200 OK
{
  "resource": {
    "data": [
      { "@ref": "classes/spells/104979509694379214" },
      { "@ref": "classes/spells/104979509692858368" },
      { "@ref": "classes/spells/104979509695139637" }
    ]
  }
}

=> {
  "data": [
    { "@ref": "classes/spells/104979509694379214" },
    { "@ref": "classes/spells/104979509692858368" },
    { "@ref": "classes/spells/104979509695139637" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/104979509694379214" },
    { "@ref": "classes/spells/104979509692858368" },
    { "@ref": "classes/spells/104979509695139637" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/104979509694379214" },
    { "@ref": "classes/spells/104979509692858368" },
    { "@ref": "classes/spells/104979509695139637" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/104979509694379214" },
    { "@ref": "classes/spells/104979509692858368" },
    { "@ref": "classes/spells/104979509695139637" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/104979509694379214" },
    { "@ref": "classes/spells/104979509692858368" },
    { "@ref": "classes/spells/104979509695139637" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/104979509694379214" },
    { "@ref": "classes/spells/104979509692858368" },
    { "@ref": "classes/spells/104979509695139637" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/104979509694379214" },
    { "@ref": "classes/spells/104979509692858368" },
    { "@ref": "classes/spells/104979509695139637" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/104979509694379214" },
    { "@ref": "classes/spells/104979509692858368" },
    { "@ref": "classes/spells/104979509695139637" }
  ]
}

With sources:


curl https://db.fauna.com/ \
    -u kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE: \
    -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(Value("spells_by_element")), Value("fire")),
        Match(Index(Value("spells_by_element")), Value("water"))))
    .sources(Value(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(
  Paginate(
    Union(
      Match(Index("spells_by_element"), "fire"),
      Match(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("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(
    f.Paginate(
        f.Union(
            f.MatchTerm(f.Index("spells_by_element"), "fire"),
            f.MatchTerm(f.Index("spells_by_element"), "water"),
        ),
        f.Sources(true),
    ),
)

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

HTTP/1.1 200 OK
{
  "resource": {
    "data": [
      {
        "value": { "@ref": "classes/spells/104979509694379214" },
        "sources": [
          {
            "@set": {
              "match": { "@ref": "indexes/spells_by_element" },
              "terms": "fire"
            }
          }
        ]
      },
      {
        "value": { "@ref": "classes/spells/104979509692858368" },
        "sources": [
          {
            "@set": {
              "match": { "@ref": "indexes/spells_by_element" },
              "terms": "fire"
            }
          },
          {
            "@set": {
              "match": { "@ref": "indexes/spells_by_element" },
              "terms": "water"
            }
          }
        ]
      },
      {
        "value": { "@ref": "classes/spells/104979509695139637" },
        "sources": [
          {
            "@set": {
              "match": { "@ref": "indexes/spells_by_element" },
              "terms": "water"
            }
          }
        ]
      }
    ]
  }
}

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

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

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

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

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

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

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

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

With events:


curl https://db.fauna.com/ \
    -u kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE: \
    -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(Value("spells_by_element")), Value("fire")),
        Match(Index(Value("spells_by_element")), Value("water"))))
    .events(Value(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(
  Paginate(
    Union(
      Match(Index("spells_by_element"), "fire"),
      Match(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("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(
    f.Paginate(
        f.Union(
            f.MatchTerm(f.Index("spells_by_element"), "fire"),
            f.MatchTerm(f.Index("spells_by_element"), "water"),
        ),
        f.Events(true),
    ),
)

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

HTTP/1.1 200 OK
{
  "resource": {
    "data": [
      {
        "ts": 1436375112199704,
        "action": "create",
        "resource": { "@ref": "classes/spells/104979509694379214" }
      },
      {
        "ts": 1436375112257866,
        "action": "create",
        "resource": { "@ref": "classes/spells/104979509692858368" }
      },
      {
        "ts": 1436375112316028,
        "action": "create",
        "resource": { "@ref": "classes/spells/104979509695139637" }
      }
    ]
  }
}

=> {
  "data": [
    {
      "ts": 1436375112199704,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" }
    },
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    },
    {
      "ts": 1436375112316028,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509695139637" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1436375112199704,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" }
    },
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    },
    {
      "ts": 1436375112316028,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509695139637" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1436375112199704,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" }
    },
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    },
    {
      "ts": 1436375112316028,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509695139637" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1436375112199704,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" }
    },
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    },
    {
      "ts": 1436375112316028,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509695139637" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1436375112199704,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" }
    },
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    },
    {
      "ts": 1436375112316028,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509695139637" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1436375112199704,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" }
    },
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    },
    {
      "ts": 1436375112316028,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509695139637" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1436375112199704,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" }
    },
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    },
    {
      "ts": 1436375112316028,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509695139637" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1436375112199704,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" }
    },
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    },
    {
      "ts": 1436375112316028,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509695139637" }
    }
  ]
}

exist(ref, [ts])

exists returns boolean true if the provided ref exists (in the case of an instance), or is non-empty (in the case of a set), and false otherwise.

Parameters
ts Integer or time value optional Existence of the ref is checked at given time (number of UNIX microseconds or time value).

curl https://db.fauna.com/ \
    -u kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE: \
    -d '{ "exists": { "@ref": "classes/spells/104979509694379214" } }'

client.query(Exists(Ref("classes/spells/104979509694379214")));

client.query(q.Exists(Ref("classes/spells/104979509694379214")));

client.query(Exists(Ref("classes/spells/104979509694379214")))

$client.query do
  exists ref('classes/spells/104979509694379214')
end

client.Query(Exists(Ref("classes/spells/104979509694379214")));

client.query(q.exists(Ref("classes/spells/104979509694379214")))

client.Query(
    f.Exists(f.Ref("classes/spells/104979509694379214")),
)

client.query(
    Exists(Ref("classes/spells/104979509694379214"))
)

HTTP/1.1 200 OK
{ "resource": true }

=> true

=> true

=> true

=> true

=> true

=> true

=> true

=> true

key_from_secret(secret)

key_from_secret retrieves a key object given the key’s secret string.


curl https://db.fauna.com/ \
    -u kqnPAi4gDivAAAC0i5t-a9YCcRnljtU2SfMJ-kWSRYI: \
    -d '{ "key_from_secret": "kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE" }'

client.query(
  KeyFromSecret(
    Value("kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE")));

client.query(
  q.KeyFromSecret("kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE"));

client.query(
  KeyFromSecret("kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE"))

$client.query do
  key_from_secret 'kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE'
end

client.Query(
  KeyFromSecret("kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE"));

client.query(
  q.key_from_secret("kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE"))

client.Query(
    f.KeyFromSecret("kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE"),
)

client.query(
    KeyFromSecret(
        "kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE"
    )
)

HTTP/1.1 200 OK
{
  "resource": {
    "ref": { "@ref": "keys/104979509695900060" },
    "class": { "@ref": "keys" },
    "ts": 1436375112141542,
    "database": { "@ref": "databases/prydain" },
    "role": "server",
    "hashed_secret": "$2a$05$.saZ/E/JSuEEkbIfTU/GN.7iKEBBpBGePtWe/mZyL/rmf4uXeZ5oi"
  }
}

=> {
  "ref": { "@ref": "keys/104979509695900060" },
  "class": { "@ref": "keys" },
  "ts": 1436375112141542,
  "database": { "@ref": "databases/prydain" },
  "role": "server",
  "hashed_secret": "$2a$05$.saZ/E/JSuEEkbIfTU/GN.7iKEBBpBGePtWe/mZyL/rmf4uXeZ5oi"
}

=> {
  "ref": { "@ref": "keys/104979509695900060" },
  "class": { "@ref": "keys" },
  "ts": 1436375112141542,
  "database": { "@ref": "databases/prydain" },
  "role": "server",
  "hashed_secret": "$2a$05$.saZ/E/JSuEEkbIfTU/GN.7iKEBBpBGePtWe/mZyL/rmf4uXeZ5oi"
}

=> {
  "ref": { "@ref": "keys/104979509695900060" },
  "class": { "@ref": "keys" },
  "ts": 1436375112141542,
  "database": { "@ref": "databases/prydain" },
  "role": "server",
  "hashed_secret": "$2a$05$.saZ/E/JSuEEkbIfTU/GN.7iKEBBpBGePtWe/mZyL/rmf4uXeZ5oi"
}

=> {
  "ref": { "@ref": "keys/104979509695900060" },
  "class": { "@ref": "keys" },
  "ts": 1436375112141542,
  "database": { "@ref": "databases/prydain" },
  "role": "server",
  "hashed_secret": "$2a$05$.saZ/E/JSuEEkbIfTU/GN.7iKEBBpBGePtWe/mZyL/rmf4uXeZ5oi"
}

=> {
  "ref": { "@ref": "keys/104979509695900060" },
  "class": { "@ref": "keys" },
  "ts": 1436375112141542,
  "database": { "@ref": "databases/prydain" },
  "role": "server",
  "hashed_secret": "$2a$05$.saZ/E/JSuEEkbIfTU/GN.7iKEBBpBGePtWe/mZyL/rmf4uXeZ5oi"
}

=> {
  "ref": { "@ref": "keys/104979509695900060" },
  "class": { "@ref": "keys" },
  "ts": 1436375112141542,
  "database": { "@ref": "databases/prydain" },
  "role": "server",
  "hashed_secret": "$2a$05$.saZ/E/JSuEEkbIfTU/GN.7iKEBBpBGePtWe/mZyL/rmf4uXeZ5oi"
}

=> {
  "ref": { "@ref": "keys/104979509695900060" },
  "class": { "@ref": "keys" },
  "ts": 1436375112141542,
  "database": { "@ref": "databases/prydain" },
  "role": "server",
  "hashed_secret": "$2a$05$.saZ/E/JSuEEkbIfTU/GN.7iKEBBpBGePtWe/mZyL/rmf4uXeZ5oi"
}

=> {
  "ref": { "@ref": "keys/104979509695900060" },
  "class": { "@ref": "keys" },
  "ts": 1436375112141542,
  "database": { "@ref": "databases/prydain" },
  "role": "server",
  "hashed_secret": "$2a$05$.saZ/E/JSuEEkbIfTU/GN.7iKEBBpBGePtWe/mZyL/rmf4uXeZ5oi"
}

Write Functions

Instances and schema configuration are created, modified, and deleted using the same set of functions. See the Object Reference for information on the valid parameters for a given class of instance.

create(class_ref, params_object)

create an instance of the class referred to by class_ref, using params_object.


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

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

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

client.query(
  Create(
    Class("spells"),
    Obj(
      "data" -> Obj(
        "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(
    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(
    f.Create(
        f.Class("spells"),
        f.Obj{
            "data": f.Obj{
                "name": "Mountainous Thunder",
                "element": "air",
                "cost": 15,
            },
        },
    ),
)

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

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

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

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

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

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

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

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

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

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

update(ref, params_object)

update updates a resource ref. Updates are partial, and only modify values that are specified. Scalar values and arrays are replaced by newer versions, objects are merged, and null removes a value.


curl https://db.fauna.com/ \
    -u kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE: \
    -d '{
          "update": { "@ref": "classes/spells/104979509696660483" },
          "params": {
            "object": {
              "data": {
                "object": { "name": "Mountain's Thunder", "cost": null }
              }
            }
          }
        }'

client.query(
  Update(
    Ref("classes/spells/104979509696660483"),
    Obj(
      "data", Obj("name", Value("Mountain's Thunder"), "cost", Null())
    )));

client.query(
  q.Update(
    Ref("classes/spells/104979509696660483"),
    { data: { name: "Mountain's Thunder", cost: null } }));

client.query(
  Update(
    Ref("classes/spells/104979509696660483"),
    Obj(
      "data" -> Obj("name" -> "Mountain's Thunder", "cost" -> Null())
    )))

$client.query do
  update ref('classes/spells/104979509696660483'),
         data: { name: "Mountain's Thunder", cost: nil }
end

client.Query(
  Update(
    Ref("classes/spells/104979509696660483"),
    Obj("data", Obj("name", "Mountain's Thunder", "cost", Null()))));

client.query(
  q.update(
    Ref("classes/spells/104979509696660483"),
    {"data": {"name": "Mountain's Thunder", "cost": None}}
  ))

client.Query(
    f.Update(
        f.Ref("classes/spells/104979509696660483"),
        f.Obj{
            "data": f.Obj{"name": "Mountain's Thunder", "cost": f.Null()},
        },
    ),
)

client.query(
    Update(
        ref: Ref("classes/spells/104979509696660483"),
        to: Obj(
            "data" => Obj("name" => "Mountain's Thunder", "cost" => nil)
        )
    )
)

HTTP/1.1 200 OK
{
  "resource": {
    "ref": { "@ref": "classes/spells/104979509696660483" },
    "class": { "@ref": "classes/spells" },
    "ts": 1436375112490514,
    "data": { "name": "Mountain's Thunder", "element": "air" }
  }
}

=> {
  "ref": { "@ref": "classes/spells/104979509696660483" },
  "class": { "@ref": "classes/spells" },
  "ts": 1436375112490514,
  "data": { "name": "Mountain's Thunder", "element": "air" }
}

=> {
  "ref": { "@ref": "classes/spells/104979509696660483" },
  "class": { "@ref": "classes/spells" },
  "ts": 1436375112490514,
  "data": { "name": "Mountain's Thunder", "element": "air" }
}

=> {
  "ref": { "@ref": "classes/spells/104979509696660483" },
  "class": { "@ref": "classes/spells" },
  "ts": 1436375112490514,
  "data": { "name": "Mountain's Thunder", "element": "air" }
}

=> {
  "ref": { "@ref": "classes/spells/104979509696660483" },
  "class": { "@ref": "classes/spells" },
  "ts": 1436375112490514,
  "data": { "name": "Mountain's Thunder", "element": "air" }
}

=> {
  "ref": { "@ref": "classes/spells/104979509696660483" },
  "class": { "@ref": "classes/spells" },
  "ts": 1436375112490514,
  "data": { "name": "Mountain's Thunder", "element": "air" }
}

=> {
  "ref": { "@ref": "classes/spells/104979509696660483" },
  "class": { "@ref": "classes/spells" },
  "ts": 1436375112490514,
  "data": { "name": "Mountain's Thunder", "element": "air" }
}

=> {
  "ref": { "@ref": "classes/spells/104979509696660483" },
  "class": { "@ref": "classes/spells" },
  "ts": 1436375112490514,
  "data": { "name": "Mountain's Thunder", "element": "air" }
}

=> {
  "ref": { "@ref": "classes/spells/104979509696660483" },
  "class": { "@ref": "classes/spells" },
  "ts": 1436375112490514,
  "data": { "name": "Mountain's Thunder", "element": "air" }
}

replace(ref, params_object)

replace replaces the resource ref using the provided params. Values not specified are removed.


curl https://db.fauna.com/ \
    -u kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE: \
    -d '{
          "replace": { "@ref": "classes/spells/104979509696660483" },
          "params": {
            "object": {
              "data": {
                "object": {
                  "name": "Mountain's Thunder",
                  "element": [ "air", "earth" ],
                  "cost": 10
                }
              }
            }
          }
        }'

client.query(
  Replace(
    Ref("classes/spells/104979509696660483"),
    Obj(
      "data", Obj(
        "name", Value("Mountain's Thunder"),
        "element", Arr(Value("air"), Value("earth")),
        "cost", Value(10)
      )
    )));

client.query(
  q.Replace(
    Ref("classes/spells/104979509696660483"),
    {
      data: {
        name: "Mountain's Thunder",
        element: ["air", "earth"],
        cost: 10
      }
    }));

client.query(
  Replace(
    Ref("classes/spells/104979509696660483"),
    Obj(
      "data" -> Obj(
        "name" -> "Mountain's Thunder",
        "element" -> Arr("air", "earth"),
        "cost" -> 10
      )
    )))

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

client.Query(
  Replace(
    Ref("classes/spells/104979509696660483"),
    Obj(
      "data", Obj(
        "name", "Mountain's Thunder",
        "element", Arr("air", "earth"),
        "cost", 10
      )
    )));

client.query(
  q.replace(
    Ref("classes/spells/104979509696660483"),
    {
      "data": {
        "name": "Mountain's Thunder",
        "element": ["air", "earth"],
        "cost": 10
      }
    }
  ))

client.Query(
    f.Replace(
        f.Ref("classes/spells/104979509696660483"),
        f.Obj{
            "data": f.Obj{
                "name": "Mountain's Thunder",
                "element": f.Arr{"air", "earth"},
                "cost": 10,
            },
        },
    ),
)

client.query(
    Replace(
        ref: Ref("classes/spells/104979509696660483"),
        with: Obj(
            "data" => Obj(
                "name" => "Mountain's Thunder",
                "element" => Arr("air", "earth"),
                "cost" => 10
            )
        )
    )
)

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

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

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

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

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

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

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

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

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

delete(ref)

delete removes a resource.


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

client.query(Delete(Ref("classes/spells/104979509696660483")));

client.query(q.Delete(Ref("classes/spells/104979509696660483")));

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

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

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

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

client.Query(
    f.Delete(f.Ref("classes/spells/104979509696660483")),
)

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

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

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

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

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

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

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

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

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

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

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

client.query(Get(Ref("classes/spells/104979509696660483")));

client.query(q.Get(Ref("classes/spells/104979509696660483")));

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

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

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

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

client.Query(f.Get(f.Ref("classes/spells/104979509696660483")))

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

HTTP/1.1 404 Not Found
{
  "errors": [
    {
      "position": [  ],
      "code": "instance not found",
      "description": "Instance not found."
    }
  ]
}

=> {
  "errors": [
    {
      "position": [  ],
      "code": "instance not found",
      "description": "Instance not found."
    }
  ]
}

=> {
  "errors": [
    {
      "position": [  ],
      "code": "instance not found",
      "description": "Instance not found."
    }
  ]
}

=> {
  "errors": [
    {
      "position": [  ],
      "code": "instance not found",
      "description": "Instance not found."
    }
  ]
}

=> {
  "errors": [
    {
      "position": [  ],
      "code": "instance not found",
      "description": "Instance not found."
    }
  ]
}

=> {
  "errors": [
    {
      "position": [  ],
      "code": "instance not found",
      "description": "Instance not found."
    }
  ]
}

=> {
  "errors": [
    {
      "position": [  ],
      "code": "instance not found",
      "description": "Instance not found."
    }
  ]
}

=> {
  "errors": [
    {
      "position": [  ],
      "code": "instance not found",
      "description": "Instance not found."
    }
  ]
}

=> {
  "errors": [
    {
      "position": [  ],
      "code": "instance not found",
      "description": "Instance not found."
    }
  ]
}

insert(ref, ts, action, params_object)

insert adds an event to an instance’s history. The ref must refer to an instance of a user-defined class or a key - all other refs result in an “invalid argument” error. Timestamp can be expressed as either a number of UNIX microseconds or as a time value.


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

client.query(
  Insert(
    Ref("classes/spells/104979509696660483"),
    Value(1),
    Action.CREATE,
    Obj(
      "data", Obj(
        "name", Value("Mountain's Thunder"),
        "cost", Value(10),
        "element", Arr(Value("air"), Value("earth"))
      )
    )));

client.query(
  q.Insert(
    Ref("classes/spells/104979509696660483"),
    1,
    "create",
    {
      data: {
        name: "Mountain's Thunder",
        cost: 10,
        element: ["air", "earth"]
      }
    }));

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

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

client.Query(
  Insert(
    Ref("classes/spells/104979509696660483"),
    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/104979509696660483"),
    ts=1,
    action="create",
    params={
      "data": {
        "name": "Mountain's Thunder",
        "cost": 10,
        "element": ["air", "earth"]
      }
    }
  ))

client.Query(
    f.Insert(
        f.Ref("classes/spells/104979509696660483"),
        1,
        f.ActionCreate,
        f.Obj{
            "data": f.Obj{
                "name": "Mountain's Thunder",
                "cost": 10,
                "element": f.Arr{"air", "earth"},
            },
        },
    ),
)

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

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

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

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

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

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

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

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

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

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

remove(ref, ts, action)

remove deletes an event from an instance’s history. The ref must refer to an instance of a user-defined class - all other refs result in an “invalid argument” error. Timestamp can be expressed as either a number of UNIX microseconds or as a time value.


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

client.query(
  Remove(
    Ref("classes/spells/104979509696660483"),
    Value(1),
    Action.CREATE));

client.query(
  q.Remove(
    Ref("classes/spells/104979509696660483"),
    1,
    "create"));

client.query(
  Remove(
    Ref("classes/spells/104979509696660483"),
    ts = 1,
    action = "create"))

$client.query do
  remove ref('classes/spells/104979509696660483'), 1, 'create'
end

client.Query(
  Remove(
    Ref("classes/spells/104979509696660483"),
    ts: 1,
    action: "create"));

client.query(
  q.remove(
    Ref("classes/spells/104979509696660483"),
    ts=1,
    action="create"
  ))

client.Query(
    f.Remove(
        f.Ref("classes/spells/104979509696660483"),
        1,
        f.ActionCreate,
    ),
)

client.query(
    Remove(
        ref: Ref("classes/spells/104979509696660483"),
        ts: 1,
        action: "create"
    )
)

HTTP/1.1 200 OK
{ "resource": null }

=> null

=> null

=> null

=> null

=> null

=> null

=> null

=> null

create_key(params_object)

create_key creates a new key with the specified params_object. It requires an admin key for authentication.


curl https://db.fauna.com/ \
    -u kqnPAi4gDivAAAC0i5t-a9YCcRnljtU2SfMJ-kWSRYI: \
    -d '{
          "create_key": {
            "object": { "database": { "database": "prydain" }, "role": "server" }
          }
        }'

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

client.query(
  q.CreateKey(
    { database: q.Database("prydain"), role: "server" }));

client.query(
  CreateKey(
    Obj("database" -> 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.create_key(
    {"database": q.database("prydain"), "role": "server"}
  ))

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

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

HTTP/1.1 201 Created
{
  "resource": {
    "ref": { "@ref": "keys/104979509697420906" },
    "class": { "@ref": "keys" },
    "ts": 1436375112665000,
    "database": { "@ref": "databases/prydain" },
    "role": "server",
    "secret": "kqnPAi3KlXEgAAC0OHSIyrIITuOMRfwre9owibw4nPU",
    "hashed_secret": "$2a$05$/FgxoctNLXMBjYAcea/dwOeyYLJtQLGiEdf2S/Lu6ZN7e6Gps6WF6"
  }
}

=> {
  "ref": { "@ref": "keys/104979509697420906" },
  "class": { "@ref": "keys" },
  "ts": 1436375112665000,
  "database": { "@ref": "databases/prydain" },
  "role": "server",
  "secret": "kqnPAi3KlXEgAAC0OHSIyrIITuOMRfwre9owibw4nPU",
  "hashed_secret": "$2a$05$/FgxoctNLXMBjYAcea/dwOeyYLJtQLGiEdf2S/Lu6ZN7e6Gps6WF6"
}

=> {
  "ref": { "@ref": "keys/104979509697420906" },
  "class": { "@ref": "keys" },
  "ts": 1436375112665000,
  "database": { "@ref": "databases/prydain" },
  "role": "server",
  "secret": "kqnPAi3KlXEgAAC0OHSIyrIITuOMRfwre9owibw4nPU",
  "hashed_secret": "$2a$05$/FgxoctNLXMBjYAcea/dwOeyYLJtQLGiEdf2S/Lu6ZN7e6Gps6WF6"
}

=> {
  "ref": { "@ref": "keys/104979509697420906" },
  "class": { "@ref": "keys" },
  "ts": 1436375112665000,
  "database": { "@ref": "databases/prydain" },
  "role": "server",
  "secret": "kqnPAi3KlXEgAAC0OHSIyrIITuOMRfwre9owibw4nPU",
  "hashed_secret": "$2a$05$/FgxoctNLXMBjYAcea/dwOeyYLJtQLGiEdf2S/Lu6ZN7e6Gps6WF6"
}

=> {
  "ref": { "@ref": "keys/104979509697420906" },
  "class": { "@ref": "keys" },
  "ts": 1436375112665000,
  "database": { "@ref": "databases/prydain" },
  "role": "server",
  "secret": "kqnPAi3KlXEgAAC0OHSIyrIITuOMRfwre9owibw4nPU",
  "hashed_secret": "$2a$05$/FgxoctNLXMBjYAcea/dwOeyYLJtQLGiEdf2S/Lu6ZN7e6Gps6WF6"
}

=> {
  "ref": { "@ref": "keys/104979509697420906" },
  "class": { "@ref": "keys" },
  "ts": 1436375112665000,
  "database": { "@ref": "databases/prydain" },
  "role": "server",
  "secret": "kqnPAi3KlXEgAAC0OHSIyrIITuOMRfwre9owibw4nPU",
  "hashed_secret": "$2a$05$/FgxoctNLXMBjYAcea/dwOeyYLJtQLGiEdf2S/Lu6ZN7e6Gps6WF6"
}

=> {
  "ref": { "@ref": "keys/104979509697420906" },
  "class": { "@ref": "keys" },
  "ts": 1436375112665000,
  "database": { "@ref": "databases/prydain" },
  "role": "server",
  "secret": "kqnPAi3KlXEgAAC0OHSIyrIITuOMRfwre9owibw4nPU",
  "hashed_secret": "$2a$05$/FgxoctNLXMBjYAcea/dwOeyYLJtQLGiEdf2S/Lu6ZN7e6Gps6WF6"
}

=> {
  "ref": { "@ref": "keys/104979509697420906" },
  "class": { "@ref": "keys" },
  "ts": 1436375112665000,
  "database": { "@ref": "databases/prydain" },
  "role": "server",
  "secret": "kqnPAi3KlXEgAAC0OHSIyrIITuOMRfwre9owibw4nPU",
  "hashed_secret": "$2a$05$/FgxoctNLXMBjYAcea/dwOeyYLJtQLGiEdf2S/Lu6ZN7e6Gps6WF6"
}

=> {
  "ref": { "@ref": "keys/104979509697420906" },
  "class": { "@ref": "keys" },
  "ts": 1436375112665000,
  "database": { "@ref": "databases/prydain" },
  "role": "server",
  "secret": "kqnPAi3KlXEgAAC0OHSIyrIITuOMRfwre9owibw4nPU",
  "hashed_secret": "$2a$05$/FgxoctNLXMBjYAcea/dwOeyYLJtQLGiEdf2S/Lu6ZN7e6Gps6WF6"
}

create_database(params_object)

create_database creates a new database with the specified params_object. It requires an admin key for authentication.it requires an admin key.


curl https://db.fauna.com/ \
    -u kqnPAi4gDivAAAC0i5t-a9YCcRnljtU2SfMJ-kWSRYI: \
    -d '{ "create_database": { "object": { "name": "db-next" } } }'

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

create_class(params_object)

create_class creates a new class with the specified params_object.


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

client.query(CreateClass(Obj("name", Value("boons"))));

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

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

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

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

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

client.Query(f.CreateClass(f.Obj{"name": "boons"}))

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

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

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

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

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

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

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

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

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

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

create_index(params_object)

create_index creates a new index with the specified params_object.


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

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

client.query(
  q.CreateIndex(
    { name: "new-index", source: q.Class("spells") }));

client.query(
  CreateIndex(
    Obj("name" -> "new-index", "source" -> Class("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.create_index(
    {"name": "new-index", "source": q.class_expr("spells")}
  ))

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

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

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

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

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

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

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

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

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

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

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

create_function(params_object)

create_function creates a new function with the specified params_object.


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

// Not available in this language yet.

// Not available in this language yet.

// Not available in this language yet.

# Not available in this language yet.

// Not available in this language yet.

# Not available in this language yet.

// Not available in this language yet.

// Not available in this language yet.

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

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

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

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

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

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

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

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

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

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 kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE: \
    -d '{
          "paginate": {
            "match": { "index": "spells_by_element" },
            "terms": "fire"
          }
        }'

client.query(
  Paginate(
      Match(Index(Value("spells_by_element")), Value("fire"))));

client.query(
  q.Paginate(q.Match(q.Index("spells_by_element"), "fire")));

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

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

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

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

client.Query(
    f.Paginate(
        f.MatchTerm(f.Index("spells_by_element"), "fire"),
    ),
)

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

HTTP/1.1 200 OK
{
  "resource": {
    "data": [
      { "@ref": "classes/spells/104979509694379214" },
      { "@ref": "classes/spells/104979509692858368" }
    ]
  }
}

=> {
  "data": [
    { "@ref": "classes/spells/104979509694379214" },
    { "@ref": "classes/spells/104979509692858368" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/104979509694379214" },
    { "@ref": "classes/spells/104979509692858368" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/104979509694379214" },
    { "@ref": "classes/spells/104979509692858368" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/104979509694379214" },
    { "@ref": "classes/spells/104979509692858368" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/104979509694379214" },
    { "@ref": "classes/spells/104979509692858368" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/104979509694379214" },
    { "@ref": "classes/spells/104979509692858368" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/104979509694379214" },
    { "@ref": "classes/spells/104979509692858368" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/104979509694379214" },
    { "@ref": "classes/spells/104979509692858368" }
  ]
}

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 kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE: \
    -d '{
          "paginate": {
            "match": { "index": "spells_by_element" },
            "terms": "fire"
          },
          "events": true
        }'

client.query(
  Paginate(
      Match(Index(Value("spells_by_element")), Value("fire")))
    .events(Value(true)));

client.query(
  q.Paginate(
    q.Match(q.Index("spells_by_element"), "fire"),
    { events: true }));

client.query(
  Paginate(
    Match(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("spells_by_element"), "fire"),
    events: true));

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

client.Query(
    f.Paginate(
        f.MatchTerm(f.Index("spells_by_element"), "fire"),
        f.Events(true),
    ),
)

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

HTTP/1.1 200 OK
{
  "resource": {
    "data": [
      {
        "ts": 1436375112199704,
        "action": "create",
        "resource": { "@ref": "classes/spells/104979509694379214" }
      },
      {
        "ts": 1436375112257866,
        "action": "create",
        "resource": { "@ref": "classes/spells/104979509692858368" }
      }
    ]
  }
}

=> {
  "data": [
    {
      "ts": 1436375112199704,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" }
    },
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1436375112199704,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" }
    },
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1436375112199704,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" }
    },
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1436375112199704,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" }
    },
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1436375112199704,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" }
    },
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1436375112199704,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" }
    },
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1436375112199704,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" }
    },
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1436375112199704,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" }
    },
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    }
  ]
}

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 kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE: \
    -d '{
          "paginate": {
            "union": [
              {
                "match": { "index": "spells_by_element" },
                "terms": "fire"
              },
              {
                "match": { "index": "spells_by_element" },
                "terms": "water"
              }
            ]
          }
        }'

client.query(
  Paginate(
      Union(
        Match(Index(Value("spells_by_element")), Value("fire")),
        Match(Index(Value("spells_by_element")), Value("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(
  Paginate(
    Union(
      Match(Index("spells_by_element"), "fire"),
      Match(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("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(
    f.Paginate(
        f.Union(
            f.MatchTerm(f.Index("spells_by_element"), "fire"),
            f.MatchTerm(f.Index("spells_by_element"), "water"),
        ),
    ),
)

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

HTTP/1.1 200 OK
{
  "resource": {
    "data": [
      { "@ref": "classes/spells/104979509694379214" },
      { "@ref": "classes/spells/104979509692858368" },
      { "@ref": "classes/spells/104979509695139637" }
    ]
  }
}

=> {
  "data": [
    { "@ref": "classes/spells/104979509694379214" },
    { "@ref": "classes/spells/104979509692858368" },
    { "@ref": "classes/spells/104979509695139637" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/104979509694379214" },
    { "@ref": "classes/spells/104979509692858368" },
    { "@ref": "classes/spells/104979509695139637" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/104979509694379214" },
    { "@ref": "classes/spells/104979509692858368" },
    { "@ref": "classes/spells/104979509695139637" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/104979509694379214" },
    { "@ref": "classes/spells/104979509692858368" },
    { "@ref": "classes/spells/104979509695139637" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/104979509694379214" },
    { "@ref": "classes/spells/104979509692858368" },
    { "@ref": "classes/spells/104979509695139637" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/104979509694379214" },
    { "@ref": "classes/spells/104979509692858368" },
    { "@ref": "classes/spells/104979509695139637" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/104979509694379214" },
    { "@ref": "classes/spells/104979509692858368" },
    { "@ref": "classes/spells/104979509695139637" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/104979509694379214" },
    { "@ref": "classes/spells/104979509692858368" },
    { "@ref": "classes/spells/104979509695139637" }
  ]
}

The events view of union contains a unified view of the source sets.


curl https://db.fauna.com/ \
    -u kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE: \
    -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(Value("spells_by_element")), Value("fire")),
        Match(Index(Value("spells_by_element")), Value("water"))))
    .events(Value(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(
  Paginate(
    Union(
      Match(Index("spells_by_element"), "fire"),
      Match(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("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(
    f.Paginate(
        f.Union(
            f.MatchTerm(f.Index("spells_by_element"), "fire"),
            f.MatchTerm(f.Index("spells_by_element"), "water"),
        ),
        f.Events(true),
    ),
)

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

HTTP/1.1 200 OK
{
  "resource": {
    "data": [
      {
        "ts": 1436375112199704,
        "action": "create",
        "resource": { "@ref": "classes/spells/104979509694379214" }
      },
      {
        "ts": 1436375112257866,
        "action": "create",
        "resource": { "@ref": "classes/spells/104979509692858368" }
      },
      {
        "ts": 1436375112316028,
        "action": "create",
        "resource": { "@ref": "classes/spells/104979509695139637" }
      }
    ]
  }
}

=> {
  "data": [
    {
      "ts": 1436375112199704,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" }
    },
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    },
    {
      "ts": 1436375112316028,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509695139637" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1436375112199704,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" }
    },
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    },
    {
      "ts": 1436375112316028,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509695139637" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1436375112199704,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" }
    },
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    },
    {
      "ts": 1436375112316028,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509695139637" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1436375112199704,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" }
    },
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    },
    {
      "ts": 1436375112316028,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509695139637" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1436375112199704,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" }
    },
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    },
    {
      "ts": 1436375112316028,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509695139637" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1436375112199704,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" }
    },
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    },
    {
      "ts": 1436375112316028,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509695139637" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1436375112199704,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" }
    },
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    },
    {
      "ts": 1436375112316028,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509695139637" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1436375112199704,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" }
    },
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    },
    {
      "ts": 1436375112316028,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509695139637" }
    }
  ]
}

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 kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE: \
    -d '{
          "paginate": {
            "intersection": [
              {
                "match": { "index": "spells_by_element" },
                "terms": "fire"
              },
              {
                "match": { "index": "spells_by_element" },
                "terms": "water"
              }
            ]
          }
        }'

client.query(
  Paginate(
      Intersection(
        Match(Index(Value("spells_by_element")), Value("fire")),
        Match(Index(Value("spells_by_element")), Value("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(
  Paginate(
    Intersection(
      Match(Index("spells_by_element"), "fire"),
      Match(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("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(
    f.Paginate(
        f.Intersection(
            f.MatchTerm(f.Index("spells_by_element"), "fire"),
            f.MatchTerm(f.Index("spells_by_element"), "water"),
        ),
    ),
)

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

HTTP/1.1 200 OK
{
  "resource": {
    "data": [ { "@ref": "classes/spells/104979509692858368" } ]
  }
}

=> { "data": [ { "@ref": "classes/spells/104979509692858368" } ] }

=> { "data": [ { "@ref": "classes/spells/104979509692858368" } ] }

=> { "data": [ { "@ref": "classes/spells/104979509692858368" } ] }

=> { "data": [ { "@ref": "classes/spells/104979509692858368" } ] }

=> { "data": [ { "@ref": "classes/spells/104979509692858368" } ] }

=> { "data": [ { "@ref": "classes/spells/104979509692858368" } ] }

=> { "data": [ { "@ref": "classes/spells/104979509692858368" } ] }

=> { "data": [ { "@ref": "classes/spells/104979509692858368" } ] }

The events view of intersection contains events for resources as they enter and exit the logical set over time.


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

client.query(
  Paginate(
      Intersection(
        Match(Index(Value("spells_by_element")), Value("fire")),
        Match(Index(Value("spells_by_element")), Value("water"))))
    .events(Value(true)));

client.query(
  q.Paginate(
    q.Intersection(
      q.Match(q.Index("spells_by_element"), "fire"),
      q.Match(q.Index("spells_by_element"), "water")),
    { events: true }));

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

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

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

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

client.Query(
    f.Paginate(
        f.Intersection(
            f.MatchTerm(f.Index("spells_by_element"), "fire"),
            f.MatchTerm(f.Index("spells_by_element"), "water"),
        ),
        f.Events(true),
    ),
)

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

HTTP/1.1 200 OK
{
  "resource": {
    "data": [
      {
        "ts": 1436375112257866,
        "action": "create",
        "resource": { "@ref": "classes/spells/104979509692858368" }
      }
    ]
  }
}

=> {
  "data": [
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    }
  ]
}

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 kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE: \
    -d '{
          "paginate": {
            "difference": [
              {
                "match": { "index": "spells_by_element" },
                "terms": "fire"
              },
              {
                "match": { "index": "spells_by_element" },
                "terms": "water"
              }
            ]
          }
        }'

client.query(
  Paginate(
      Difference(
        Match(Index(Value("spells_by_element")), Value("fire")),
        Match(Index(Value("spells_by_element")), Value("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(
  Paginate(
    Difference(
      Match(Index("spells_by_element"), "fire"),
      Match(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("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(
    f.Paginate(
        f.Difference(
            f.MatchTerm(f.Index("spells_by_element"), "fire"),
            f.MatchTerm(f.Index("spells_by_element"), "water"),
        ),
    ),
)

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

HTTP/1.1 200 OK
{
  "resource": {
    "data": [ { "@ref": "classes/spells/104979509694379214" } ]
  }
}

=> { "data": [ { "@ref": "classes/spells/104979509694379214" } ] }

=> { "data": [ { "@ref": "classes/spells/104979509694379214" } ] }

=> { "data": [ { "@ref": "classes/spells/104979509694379214" } ] }

=> { "data": [ { "@ref": "classes/spells/104979509694379214" } ] }

=> { "data": [ { "@ref": "classes/spells/104979509694379214" } ] }

=> { "data": [ { "@ref": "classes/spells/104979509694379214" } ] }

=> { "data": [ { "@ref": "classes/spells/104979509694379214" } ] }

=> { "data": [ { "@ref": "classes/spells/104979509694379214" } ] }

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 kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE: \
    -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(Value("spells_by_element")), Value("fire")),
        Match(Index(Value("spells_by_element")), Value("water"))))
    .events(Value(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(
  Paginate(
    Difference(
      Match(Index("spells_by_element"), "fire"),
      Match(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("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(
    f.Paginate(
        f.Difference(
            f.MatchTerm(f.Index("spells_by_element"), "fire"),
            f.MatchTerm(f.Index("spells_by_element"), "water"),
        ),
        f.Events(true),
    ),
)

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

HTTP/1.1 200 OK
{
  "resource": {
    "data": [
      {
        "ts": 1436375112199704,
        "action": "create",
        "resource": { "@ref": "classes/spells/104979509694379214" }
      },
      {
        "ts": 1436375112257866,
        "action": "create",
        "resource": { "@ref": "classes/spells/104979509692858368" }
      },
      {
        "ts": 1436375112257866,
        "action": "delete",
        "resource": { "@ref": "classes/spells/104979509692858368" }
      }
    ]
  }
}

=> {
  "data": [
    {
      "ts": 1436375112199704,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" }
    },
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    },
    {
      "ts": 1436375112257866,
      "action": "delete",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1436375112199704,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" }
    },
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    },
    {
      "ts": 1436375112257866,
      "action": "delete",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1436375112199704,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" }
    },
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    },
    {
      "ts": 1436375112257866,
      "action": "delete",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1436375112199704,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" }
    },
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    },
    {
      "ts": 1436375112257866,
      "action": "delete",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1436375112199704,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" }
    },
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    },
    {
      "ts": 1436375112257866,
      "action": "delete",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1436375112199704,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" }
    },
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    },
    {
      "ts": 1436375112257866,
      "action": "delete",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1436375112199704,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" }
    },
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    },
    {
      "ts": 1436375112257866,
      "action": "delete",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1436375112199704,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" }
    },
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    },
    {
      "ts": 1436375112257866,
      "action": "delete",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    }
  ]
}

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 kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE: \
    -d '{ "paginate": { "match": { "index": "elements_of_spells" } } }'

client.query(
  Paginate(Match(Index(Value("elements_of_spells")))));

client.query(q.Paginate(q.Match(q.Index("elements_of_spells"))));

client.query(Paginate(Match(Index("elements_of_spells"))))

$client.query do
  paginate match(index('elements_of_spells'))
end

client.Query(Paginate(Match(Index("elements_of_spells"))));

client.query(q.paginate(q.match(q.index("elements_of_spells"))))

client.Query(f.Paginate(f.Match(f.Index("elements_of_spells"))))

client.query(
    Paginate(Match(index: Index("elements_of_spells")))
)

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" ]
}

=> {
  "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 kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE: \
    -d '{
          "paginate": {
            "distinct": { "match": { "index": "elements_of_spells" } }
          }
        }'

client.query(
  Paginate(Distinct(Match(Index(Value("elements_of_spells"))))));

client.query(
  q.Paginate(q.Distinct(q.Match(q.Index("elements_of_spells")))));

client.query(
  Paginate(Distinct(Match(Index("elements_of_spells")))))

$client.query do
  paginate distinct(match(index('elements_of_spells')))
end

client.Query(
  Paginate(Distinct(Match(Index("elements_of_spells")))));

client.query(
  q.paginate(q.distinct(q.match(q.index("elements_of_spells")))))

client.Query(
    f.Paginate(
        f.Distinct(f.Match(f.Index("elements_of_spells"))),
    ),
)

client.query(
    Paginate(
        Distinct(Match(index: Index("elements_of_spells")))
    )
)

HTTP/1.1 200 OK
{ "resource": { "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" ] }

=> { "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 kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE: \
    -d '{
          "paginate": {
            "distinct": { "match": { "index": "elements_of_spells" } }
          },
          "events": true
        }'

client.query(
  Paginate(Distinct(Match(Index(Value("elements_of_spells")))))
    .events(Value(true)));

client.query(
  q.Paginate(
    q.Distinct(q.Match(q.Index("elements_of_spells"))),
    { events: true }));

client.query(
  Paginate(
    Distinct(Match(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("elements_of_spells"))),
    events: true));

client.query(
  q.paginate(
    q.distinct(q.match(q.index("elements_of_spells"))),
    events=True
  ))

client.Query(
    f.Paginate(
        f.Distinct(f.Match(f.Index("elements_of_spells"))),
        f.Events(true),
    ),
)

client.query(
    Paginate(
        Distinct(Match(index: Index("elements_of_spells"))),
        events: true
    )
)

HTTP/1.1 200 OK
{
  "resource": {
    "data": [
      {
        "ts": 1436375112199704,
        "action": "create",
        "resource": { "@ref": "classes/spells/104979509694379214" },
        "values": [ "air" ]
      },
      {
        "ts": 1436375112199704,
        "action": "create",
        "resource": { "@ref": "classes/spells/104979509694379214" },
        "values": [ "fire" ]
      },
      {
        "ts": 1436375112257866,
        "action": "create",
        "resource": { "@ref": "classes/spells/104979509692858368" },
        "values": [ "fire" ]
      },
      {
        "ts": 1436375112257866,
        "action": "create",
        "resource": { "@ref": "classes/spells/104979509692858368" },
        "values": [ "water" ]
      },
      {
        "ts": 1436375112316028,
        "action": "create",
        "resource": { "@ref": "classes/spells/104979509695139637" },
        "values": [ "earth" ]
      },
      {
        "ts": 1436375112316028,
        "action": "create",
        "resource": { "@ref": "classes/spells/104979509695139637" },
        "values": [ "water" ]
      },
      {
        "ts": 1436375112432352,
        "action": "create",
        "resource": { "@ref": "classes/spells/104979509696660483" },
        "values": [ "air" ]
      },
      {
        "ts": 1436375112548676,
        "action": "create",
        "resource": { "@ref": "classes/spells/104979509696660483" },
        "values": [ "earth" ]
      },
      {
        "ts": 1436375112606838,
        "action": "delete",
        "resource": { "@ref": "classes/spells/104979509696660483" },
        "values": [ "air" ]
      },
      {
        "ts": 1436375112606838,
        "action": "delete",
        "resource": { "@ref": "classes/spells/104979509696660483" },
        "values": [ "earth" ]
      }
    ]
  }
}

=> {
  "data": [
    {
      "ts": 1436375112199704,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" },
      "values": [ "air" ]
    },
    {
      "ts": 1436375112199704,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" },
      "values": [ "fire" ]
    },
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" },
      "values": [ "fire" ]
    },
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" },
      "values": [ "water" ]
    },
    {
      "ts": 1436375112316028,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509695139637" },
      "values": [ "earth" ]
    },
    {
      "ts": 1436375112316028,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509695139637" },
      "values": [ "water" ]
    },
    {
      "ts": 1436375112432352,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509696660483" },
      "values": [ "air" ]
    },
    {
      "ts": 1436375112548676,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509696660483" },
      "values": [ "earth" ]
    },
    {
      "ts": 1436375112606838,
      "action": "delete",
      "resource": { "@ref": "classes/spells/104979509696660483" },
      "values": [ "air" ]
    },
    {
      "ts": 1436375112606838,
      "action": "delete",
      "resource": { "@ref": "classes/spells/104979509696660483" },
      "values": [ "earth" ]
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1436375112199704,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" },
      "values": [ "air" ]
    },
    {
      "ts": 1436375112199704,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" },
      "values": [ "fire" ]
    },
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" },
      "values": [ "fire" ]
    },
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" },
      "values": [ "water" ]
    },
    {
      "ts": 1436375112316028,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509695139637" },
      "values": [ "earth" ]
    },
    {
      "ts": 1436375112316028,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509695139637" },
      "values": [ "water" ]
    },
    {
      "ts": 1436375112432352,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509696660483" },
      "values": [ "air" ]
    },
    {
      "ts": 1436375112548676,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509696660483" },
      "values": [ "earth" ]
    },
    {
      "ts": 1436375112606838,
      "action": "delete",
      "resource": { "@ref": "classes/spells/104979509696660483" },
      "values": [ "air" ]
    },
    {
      "ts": 1436375112606838,
      "action": "delete",
      "resource": { "@ref": "classes/spells/104979509696660483" },
      "values": [ "earth" ]
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1436375112199704,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" },
      "values": [ "air" ]
    },
    {
      "ts": 1436375112199704,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" },
      "values": [ "fire" ]
    },
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" },
      "values": [ "fire" ]
    },
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" },
      "values": [ "water" ]
    },
    {
      "ts": 1436375112316028,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509695139637" },
      "values": [ "earth" ]
    },
    {
      "ts": 1436375112316028,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509695139637" },
      "values": [ "water" ]
    },
    {
      "ts": 1436375112432352,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509696660483" },
      "values": [ "air" ]
    },
    {
      "ts": 1436375112548676,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509696660483" },
      "values": [ "earth" ]
    },
    {
      "ts": 1436375112606838,
      "action": "delete",
      "resource": { "@ref": "classes/spells/104979509696660483" },
      "values": [ "air" ]
    },
    {
      "ts": 1436375112606838,
      "action": "delete",
      "resource": { "@ref": "classes/spells/104979509696660483" },
      "values": [ "earth" ]
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1436375112199704,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" },
      "values": [ "air" ]
    },
    {
      "ts": 1436375112199704,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" },
      "values": [ "fire" ]
    },
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" },
      "values": [ "fire" ]
    },
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" },
      "values": [ "water" ]
    },
    {
      "ts": 1436375112316028,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509695139637" },
      "values": [ "earth" ]
    },
    {
      "ts": 1436375112316028,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509695139637" },
      "values": [ "water" ]
    },
    {
      "ts": 1436375112432352,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509696660483" },
      "values": [ "air" ]
    },
    {
      "ts": 1436375112548676,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509696660483" },
      "values": [ "earth" ]
    },
    {
      "ts": 1436375112606838,
      "action": "delete",
      "resource": { "@ref": "classes/spells/104979509696660483" },
      "values": [ "air" ]
    },
    {
      "ts": 1436375112606838,
      "action": "delete",
      "resource": { "@ref": "classes/spells/104979509696660483" },
      "values": [ "earth" ]
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1436375112199704,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" },
      "values": [ "air" ]
    },
    {
      "ts": 1436375112199704,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" },
      "values": [ "fire" ]
    },
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" },
      "values": [ "fire" ]
    },
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" },
      "values": [ "water" ]
    },
    {
      "ts": 1436375112316028,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509695139637" },
      "values": [ "earth" ]
    },
    {
      "ts": 1436375112316028,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509695139637" },
      "values": [ "water" ]
    },
    {
      "ts": 1436375112432352,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509696660483" },
      "values": [ "air" ]
    },
    {
      "ts": 1436375112548676,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509696660483" },
      "values": [ "earth" ]
    },
    {
      "ts": 1436375112606838,
      "action": "delete",
      "resource": { "@ref": "classes/spells/104979509696660483" },
      "values": [ "air" ]
    },
    {
      "ts": 1436375112606838,
      "action": "delete",
      "resource": { "@ref": "classes/spells/104979509696660483" },
      "values": [ "earth" ]
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1436375112199704,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" },
      "values": [ "air" ]
    },
    {
      "ts": 1436375112199704,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" },
      "values": [ "fire" ]
    },
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" },
      "values": [ "fire" ]
    },
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" },
      "values": [ "water" ]
    },
    {
      "ts": 1436375112316028,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509695139637" },
      "values": [ "earth" ]
    },
    {
      "ts": 1436375112316028,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509695139637" },
      "values": [ "water" ]
    },
    {
      "ts": 1436375112432352,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509696660483" },
      "values": [ "air" ]
    },
    {
      "ts": 1436375112548676,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509696660483" },
      "values": [ "earth" ]
    },
    {
      "ts": 1436375112606838,
      "action": "delete",
      "resource": { "@ref": "classes/spells/104979509696660483" },
      "values": [ "air" ]
    },
    {
      "ts": 1436375112606838,
      "action": "delete",
      "resource": { "@ref": "classes/spells/104979509696660483" },
      "values": [ "earth" ]
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1436375112199704,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" },
      "values": [ "air" ]
    },
    {
      "ts": 1436375112199704,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" },
      "values": [ "fire" ]
    },
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" },
      "values": [ "fire" ]
    },
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" },
      "values": [ "water" ]
    },
    {
      "ts": 1436375112316028,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509695139637" },
      "values": [ "earth" ]
    },
    {
      "ts": 1436375112316028,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509695139637" },
      "values": [ "water" ]
    },
    {
      "ts": 1436375112432352,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509696660483" },
      "values": [ "air" ]
    },
    {
      "ts": 1436375112548676,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509696660483" },
      "values": [ "earth" ]
    },
    {
      "ts": 1436375112606838,
      "action": "delete",
      "resource": { "@ref": "classes/spells/104979509696660483" },
      "values": [ "air" ]
    },
    {
      "ts": 1436375112606838,
      "action": "delete",
      "resource": { "@ref": "classes/spells/104979509696660483" },
      "values": [ "earth" ]
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1436375112199704,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" },
      "values": [ "air" ]
    },
    {
      "ts": 1436375112199704,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" },
      "values": [ "fire" ]
    },
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" },
      "values": [ "fire" ]
    },
    {
      "ts": 1436375112257866,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" },
      "values": [ "water" ]
    },
    {
      "ts": 1436375112316028,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509695139637" },
      "values": [ "earth" ]
    },
    {
      "ts": 1436375112316028,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509695139637" },
      "values": [ "water" ]
    },
    {
      "ts": 1436375112432352,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509696660483" },
      "values": [ "air" ]
    },
    {
      "ts": 1436375112548676,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509696660483" },
      "values": [ "earth" ]
    },
    {
      "ts": 1436375112606838,
      "action": "delete",
      "resource": { "@ref": "classes/spells/104979509696660483" },
      "values": [ "air" ]
    },
    {
      "ts": 1436375112606838,
      "action": "delete",
      "resource": { "@ref": "classes/spells/104979509696660483" },
      "values": [ "earth" ]
    }
  ]
}

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 kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE: \
    -d '{
          "paginate": {
            "join": {
              "match": { "index": "spellbooks_by_owner" },
              "terms": { "@ref": "classes/characters/104979509698181329" }
            },
            "with": { "index": "spells_by_spellbook" }
          }
        }'

client.query(
  Paginate(
      Join(
        Match(
          Index(Value("spellbooks_by_owner")),
          Ref("classes/characters/104979509698181329")),
        Index(Value("spells_by_spellbook")))));

client.query(
  q.Paginate(
    q.Join(
      q.Match(
        q.Index("spellbooks_by_owner"),
        Ref("classes/characters/104979509698181329")),
      q.Index("spells_by_spellbook"))));

client.query(
  Paginate(
    Join(
      Match(
        Index("spellbooks_by_owner"),
        Ref("classes/characters/104979509698181329")),
      Index("spells_by_spellbook"))))

$client.query do
  paginate join match(index('spellbooks_by_owner'),
                 ref('classes/characters/104979509698181329')) index('spells_by_spellbook')
end

client.Query(
  Paginate(
    Join(
      Match(
        Index("spellbooks_by_owner"),
        Ref("classes/characters/104979509698181329")),
      Index("spells_by_spellbook"))));

client.query(
  q.paginate(
    q.join(
      q.match(
        q.index("spellbooks_by_owner"),
        Ref("classes/characters/104979509698181329")
      ),
      q.index("spells_by_spellbook")
    )
  ))

client.Query(
    f.Paginate(
        f.Join(
            f.MatchTerm(
                f.Index("spellbooks_by_owner"),
                f.Ref("classes/characters/104979509698181329"),
            ),
            f.Index("spells_by_spellbook"),
        ),
    ),
)

client.query(
    Paginate(
        Join(
            Match(
                index: Index("spellbooks_by_owner"),
                terms: Ref("classes/characters/104979509698181329")
            ),
            with: Index("spells_by_spellbook")
        )
    )
)

HTTP/1.1 200 OK
{
  "resource": {
    "data": [
      { "@ref": "classes/spells/104979509694379214" },
      { "@ref": "classes/spells/104979509692858368" }
    ]
  }
}

=> {
  "data": [
    { "@ref": "classes/spells/104979509694379214" },
    { "@ref": "classes/spells/104979509692858368" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/104979509694379214" },
    { "@ref": "classes/spells/104979509692858368" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/104979509694379214" },
    { "@ref": "classes/spells/104979509692858368" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/104979509694379214" },
    { "@ref": "classes/spells/104979509692858368" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/104979509694379214" },
    { "@ref": "classes/spells/104979509692858368" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/104979509694379214" },
    { "@ref": "classes/spells/104979509692858368" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/104979509694379214" },
    { "@ref": "classes/spells/104979509692858368" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/104979509694379214" },
    { "@ref": "classes/spells/104979509692858368" }
  ]
}

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 kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE: \
    -d '{
          "paginate": {
            "join": {
              "match": { "index": "spellbooks_by_owner" },
              "terms": { "@ref": "classes/characters/104979509698181329" }
            },
            "with": {
              "lambda": "spellbook",
              "expr": {
                "match": { "index": "spells_by_spellbook" },
                "terms": { "var": "spellbook" }
              }
            }
          }
        }'

client.query(
  Paginate(
      Join(
        Match(
          Index(Value("spellbooks_by_owner")),
          Ref("classes/characters/104979509698181329")),
        Lambda(
          Value("spellbook"),
          Match(
            Index(Value("spells_by_spellbook")),
            Var("spellbook"))))));

client.query(
  q.Paginate(
    q.Join(
      q.Match(
        q.Index("spellbooks_by_owner"),
        Ref("classes/characters/104979509698181329")),
      function(spellbook) {
        return q.Match(q.Index("spells_by_spellbook"), spellbook);
      })));

client.query(
  Paginate(
    Join(
      Match(
        Index("spellbooks_by_owner"),
        Ref("classes/characters/104979509698181329")),
      Lambda { spellbook =>
        Match(Index("spells_by_spellbook"), spellbook)
      })))

$client.query do
  paginate join(match(index('spellbooks_by_owner'),
                      ref('classes/characters/104979509698181329')),
                lambda_expr('spellbook',
                            match(index('spells_by_spellbook'), var('spellbook'))))
end

client.Query(
  Paginate(
    Join(
      Match(
        Index("spellbooks_by_owner"),
        Ref("classes/characters/104979509698181329")),
      Lambda(
        "spellbook",
        Match(Index("spells_by_spellbook"), Var("spellbook"))))));

client.query(
  q.paginate(
    q.join(
      q.match(
        q.index("spellbooks_by_owner"),
        Ref("classes/characters/104979509698181329")
      ),
      q.lambda_expr(
        "spellbook",
        q.match(
          q.index("spells_by_spellbook"),
          q.var("spellbook")
        )
      )
    )
  ))

client.Query(
    f.Paginate(
        f.Join(
            f.MatchTerm(
                f.Index("spellbooks_by_owner"),
                f.Ref("classes/characters/104979509698181329"),
            ),
            f.Lambda(
                "spellbook",
                f.MatchTerm(
                    f.Index("spells_by_spellbook"),
                    f.Var("spellbook"),
                ),
            ),
        ),
    ),
)

client.query(
    Paginate(
        Join(
            Match(
                index: Index("spellbooks_by_owner"),
                terms: Ref("classes/characters/104979509698181329")
            ),
            with: Lambda(
                vars: "spellbook"
                in: Match(
                    index: Index("spells_by_spellbook"),
                    terms: Var("spellbook")
                )
            )
        )
    )
)

HTTP/1.1 200 OK
{
  "resource": {
    "data": [
      { "@ref": "classes/spells/104979509694379214" },
      { "@ref": "classes/spells/104979509692858368" }
    ]
  }
}

=> {
  "data": [
    { "@ref": "classes/spells/104979509694379214" },
    { "@ref": "classes/spells/104979509692858368" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/104979509694379214" },
    { "@ref": "classes/spells/104979509692858368" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/104979509694379214" },
    { "@ref": "classes/spells/104979509692858368" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/104979509694379214" },
    { "@ref": "classes/spells/104979509692858368" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/104979509694379214" },
    { "@ref": "classes/spells/104979509692858368" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/104979509694379214" },
    { "@ref": "classes/spells/104979509692858368" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/104979509694379214" },
    { "@ref": "classes/spells/104979509692858368" }
  ]
}

=> {
  "data": [
    { "@ref": "classes/spells/104979509694379214" },
    { "@ref": "classes/spells/104979509692858368" }
  ]
}

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 kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE: \
    -d '{
          "paginate": {
            "join": {
              "match": { "index": "spellbooks_by_owner" },
              "terms": { "@ref": "classes/characters/104979509698181329" }
            },
            "with": {
              "lambda": "spellbook",
              "expr": {
                "match": { "index": "spells_by_spellbook" },
                "terms": { "var": "spellbook" }
              }
            }
          },
          "events": true
        }'

client.query(
  Paginate(
      Join(
        Match(
          Index(Value("spellbooks_by_owner")),
          Ref("classes/characters/104979509698181329")),
        Lambda(
          Value("spellbook"),
          Match(
            Index(Value("spells_by_spellbook")),
            Var("spellbook")))))
    .events(Value(true)));

client.query(
  q.Paginate(
    q.Join(
      q.Match(
        q.Index("spellbooks_by_owner"),
        Ref("classes/characters/104979509698181329")),
      function(spellbook) {
        return q.Match(q.Index("spells_by_spellbook"), spellbook);
      }),
    { events: true }));

client.query(
  Paginate(
    Join(
      Match(
        Index("spellbooks_by_owner"),
        Ref("classes/characters/104979509698181329")),
      Lambda { spellbook =>
        Match(Index("spells_by_spellbook"), spellbook)
      }),
    events = true))

$client.query do
  paginate join(match(index('spellbooks_by_owner'),
                      ref('classes/characters/104979509698181329')),
                lambda_expr('spellbook',
                            match(index('spells_by_spellbook'), var('spellbook')))),
           events: true
end

client.Query(
  Paginate(
    Join(
      Match(
        Index("spellbooks_by_owner"),
        Ref("classes/characters/104979509698181329")),
      Lambda(
        "spellbook",
        Match(Index("spells_by_spellbook"), Var("spellbook")))),
    events: true));

client.query(
  q.paginate(
    q.join(
      q.match(
        q.index("spellbooks_by_owner"),
        Ref("classes/characters/104979509698181329")
      ),
      q.lambda_expr(
        "spellbook",
        q.match(
          q.index("spells_by_spellbook"),
          q.var("spellbook")
        )
      )
    ),
    events=True
  ))

client.Query(
    f.Paginate(
        f.Join(
            f.MatchTerm(
                f.Index("spellbooks_by_owner"),
                f.Ref("classes/characters/104979509698181329"),
            ),
            f.Lambda(
                "spellbook",
                f.MatchTerm(
                    f.Index("spells_by_spellbook"),
                    f.Var("spellbook"),
                ),
            ),
        ),
        f.Events(true),
    ),
)

client.query(
    Paginate(
        Join(
            Match(
                index: Index("spellbooks_by_owner"),
                terms: Ref("classes/characters/104979509698181329")
            ),
            with: Lambda(
                vars: "spellbook"
                in: Match(
                    index: Index("spells_by_spellbook"),
                    terms: Var("spellbook")
                )
            )
        ),
        events: true
    )
)

HTTP/1.1 200 OK
{
  "resource": {
    "data": [
      {
        "ts": 1436375112374190,
        "action": "create",
        "resource": { "@ref": "classes/spells/104979509694379214" }
      },
      {
        "ts": 1436375112374190,
        "action": "create",
        "resource": { "@ref": "classes/spells/104979509692858368" }
      }
    ]
  }
}

=> {
  "data": [
    {
      "ts": 1436375112374190,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" }
    },
    {
      "ts": 1436375112374190,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1436375112374190,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" }
    },
    {
      "ts": 1436375112374190,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1436375112374190,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" }
    },
    {
      "ts": 1436375112374190,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1436375112374190,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" }
    },
    {
      "ts": 1436375112374190,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1436375112374190,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" }
    },
    {
      "ts": 1436375112374190,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1436375112374190,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" }
    },
    {
      "ts": 1436375112374190,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1436375112374190,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" }
    },
    {
      "ts": 1436375112374190,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    }
  ]
}

=> {
  "data": [
    {
      "ts": 1436375112374190,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509694379214" }
    },
    {
      "ts": 1436375112374190,
      "action": "create",
      "resource": { "@ref": "classes/spells/104979509692858368" }
    }
  ]
}

Authentication

login(ref, params_object)

login creates a token for the provided ref.


curl https://db.fauna.com/ \
    -u kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE: \
    -d '{
          "login": { "@ref": "classes/characters/104979509698181329" },
          "params": { "object": { "password": "abracadabra" } }
        }'

client.query(
  Login(
    Ref("classes/characters/104979509698181329"),
    Obj("password", Value("abracadabra"))));

client.query(
  q.Login(
    Ref("classes/characters/104979509698181329"),
    { password: "abracadabra" }));

client.query(
  Login(
    Ref("classes/characters/104979509698181329"),
    Obj("password" -> "abracadabra")))

$client.query do
  login ref('classes/characters/104979509698181329'),
        password: 'abracadabra'
end

client.Query(
  Login(
    Ref("classes/characters/104979509698181329"),
    Obj("password", "abracadabra")));

client.query(
  q.login(
    Ref("classes/characters/104979509698181329"),
    {"password": "abracadabra"}
  ))

client.Query(
    f.Login(
        f.Ref("classes/characters/104979509698181329"),
        f.Obj{"password": "abracadabra"},
    ),
)

client.query(
    Login(
        for: Ref("classes/characters/104979509698181329"),
        Obj("password" => "abracadabra")
    )
)

HTTP/1.1 201 Created
{
  "resource": {
    "ref": { "@ref": "tokens/104979509698941752" },
    "class": { "@ref": "tokens" },
    "ts": 1436375112955810,
    "instance": { "@ref": "classes/characters/104979509698181329" },
    "secret": "k6oCLcqe9TAAAAADqc8CLcqVdZAAALQaz43VUOEOvexWVMNr3vjvZfLVCA"
  }
}

=> {
  "ref": { "@ref": "tokens/104979509698941752" },
  "class": { "@ref": "tokens" },
  "ts": 1436375112955810,
  "instance": { "@ref": "classes/characters/104979509698181329" },
  "secret": "k6oCLcqe9TAAAAADqc8CLcqVdZAAALQaz43VUOEOvexWVMNr3vjvZfLVCA"
}

=> {
  "ref": { "@ref": "tokens/104979509698941752" },
  "class": { "@ref": "tokens" },
  "ts": 1436375112955810,
  "instance": { "@ref": "classes/characters/104979509698181329" },
  "secret": "k6oCLcqe9TAAAAADqc8CLcqVdZAAALQaz43VUOEOvexWVMNr3vjvZfLVCA"
}

=> {
  "ref": { "@ref": "tokens/104979509698941752" },
  "class": { "@ref": "tokens" },
  "ts": 1436375112955810,
  "instance": { "@ref": "classes/characters/104979509698181329" },
  "secret": "k6oCLcqe9TAAAAADqc8CLcqVdZAAALQaz43VUOEOvexWVMNr3vjvZfLVCA"
}

=> {
  "ref": { "@ref": "tokens/104979509698941752" },
  "class": { "@ref": "tokens" },
  "ts": 1436375112955810,
  "instance": { "@ref": "classes/characters/104979509698181329" },
  "secret": "k6oCLcqe9TAAAAADqc8CLcqVdZAAALQaz43VUOEOvexWVMNr3vjvZfLVCA"
}

=> {
  "ref": { "@ref": "tokens/104979509698941752" },
  "class": { "@ref": "tokens" },
  "ts": 1436375112955810,
  "instance": { "@ref": "classes/characters/104979509698181329" },
  "secret": "k6oCLcqe9TAAAAADqc8CLcqVdZAAALQaz43VUOEOvexWVMNr3vjvZfLVCA"
}

=> {
  "ref": { "@ref": "tokens/104979509698941752" },
  "class": { "@ref": "tokens" },
  "ts": 1436375112955810,
  "instance": { "@ref": "classes/characters/104979509698181329" },
  "secret": "k6oCLcqe9TAAAAADqc8CLcqVdZAAALQaz43VUOEOvexWVMNr3vjvZfLVCA"
}

=> {
  "ref": { "@ref": "tokens/104979509698941752" },
  "class": { "@ref": "tokens" },
  "ts": 1436375112955810,
  "instance": { "@ref": "classes/characters/104979509698181329" },
  "secret": "k6oCLcqe9TAAAAADqc8CLcqVdZAAALQaz43VUOEOvexWVMNr3vjvZfLVCA"
}

=> {
  "ref": { "@ref": "tokens/104979509698941752" },
  "class": { "@ref": "tokens" },
  "ts": 1436375112955810,
  "instance": { "@ref": "classes/characters/104979509698181329" },
  "secret": "k6oCLcqe9TAAAAADqc8CLcqVdZAAALQaz43VUOEOvexWVMNr3vjvZfLVCA"
}

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 k6oCLcqe9TAAAAADqc8CLcqVdZAAALQaz43VUOEOvexWVMNr3vjvZfLVCA: \
    -d '{ "logout": true }'

client.query(Logout(Value(true)));

client.query(q.Logout(true));

client.query(Logout(true))

$client.query do
  logout true
end

client.Query(Logout(true));

client.query(q.logout(True))

client.Query(f.Logout(true))

client.query(Logout(all: true))

HTTP/1.1 200 OK
{ "resource": true }

=> true

=> true

=> true

=> true

=> true

=> true

=> true

=> 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 kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE: \
    -d '{
          "identify": { "@ref": "classes/characters/104979509698181329" },
          "password": "abracadabra"
        }'

client.query(
  Identify(
    Ref("classes/characters/104979509698181329"),
    Value("abracadabra")));

client.query(
  q.Identify(
    Ref("classes/characters/104979509698181329"),
    "abracadabra"));

client.query(
  Identify(
    Ref("classes/characters/104979509698181329"),
    "abracadabra"))

$client.query do
  identify ref('classes/characters/104979509698181329'),
           'abracadabra'
end

client.Query(
  Identify(
    Ref("classes/characters/104979509698181329"),
    "abracadabra"));

client.query(
  q.identify(
    Ref("classes/characters/104979509698181329"),
    "abracadabra"
  ))

client.Query(
    f.Identify(
        f.Ref("classes/characters/104979509698181329"),
        "abracadabra",
    ),
)

client.query(
    Identify(
        ref: Ref("classes/characters/104979509698181329"),
        password: "abracadabra"
    )
)

HTTP/1.1 200 OK
{ "resource": true }

=> true

=> true

=> true

=> true

=> true

=> true

=> true

=> true

{ "identity": null }

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 kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE: \
    -d '{ "identity": null }'

// Not available in this language yet.

// Not available in this language yet.

// Not available in this language yet.

# Not available in this language yet.

// Not available in this language yet.

# Not available in this language yet.

// Not available in this language yet.

// Not available in this language yet.

{ "has_identity": null }

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 kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE: \
    -d '{ "has_identity": null }'

// Not available in this language yet.

// Not available in this language yet.

// Not available in this language yet.

# Not available in this language yet.

// Not available in this language yet.

# Not available in this language yet.

// Not available in this language yet.

// Not available in this language yet.

String Functions

concat(str_1, str_2, ...)

concat joins a list of strings into a single string value.

Parameters
separator String optional A string separating each element in the result.

curl https://db.fauna.com/ \
    -u kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE: \
    -d '{ "concat": [ "Hen", "Wen" ], "separator": " " }'

client.query(
  Concat(Arr(Value("Hen"), Value("Wen")), Value(" ")));

client.query(q.Concat(["Hen", "Wen"], " "));

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

$client.query do
  concat ['Hen', 'Wen'], ' '
end

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

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

client.Query(f.Concat(f.Arr{"Hen", "Wen"}, f.Separator(" ")))

client.query(Concat("Hen", "Wen", separator: " "))

HTTP/1.1 200 OK
{ "resource": "Hen Wen" }

=> "Hen Wen"

=> "Hen Wen"

=> "Hen Wen"

=> "Hen Wen"

=> "Hen Wen"

=> "Hen Wen"

=> "Hen Wen"

=> "Hen Wen"

casefold(str)

casefold normalizes strings according to the Unicode Standard section 5.18 “Case Mappings”. By default FaunaDB uses NKFCCaseFold as recommended by the W3C (https://www.w3.org/TR/charmod-norm/).

To compare two strings for case-insensitive matching, transform each string and use a binary comparison, such as equals.

Parameters
normalizer String optional A string representing the normalizer to use. Must be one of ‘NFKCCaseFold’, ‘NFC’, ‘NFD’, ‘NFKC’, ‘NFKD’.

curl https://db.fauna.com/ \
    -u kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE: \
    -d '{ "casefold": "Hen Wen" }'

client.query(Casefold(Value("Hen Wen")));

client.query(q.Casefold("Hen Wen"));

client.query(Casefold("Hen Wen"))

$client.query do
  casefold 'Hen Wen'
end

client.Query(Casefold("Hen Wen"));

client.query(q.casefold("Hen Wen"))

client.Query(f.Casefold("Hen Wen"))

client.query(Casefold("Hen Wen"))

HTTP/1.1 200 OK
{ "resource": "hen wen" }

=> "hen wen"

=> "hen wen"

=> "hen wen"

=> "hen wen"

=> "hen wen"

=> "hen wen"

=> "hen wen"

=> "hen wen"

Time and Date

time(str)

time constructs a time special type from an ISO 8601 offset date/time 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 query will be equal.


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

client.query(Time(Value("1970-01-01T00:00:00+00:00")));

client.query(q.Time("1970-01-01T00:00:00+00:00"));

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

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

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

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

client.Query(f.Time("1970-01-01T00:00:00+00:00"))

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

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

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

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

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

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

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

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

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

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

epoch(num, unit)

epoch constructs a time special type relative to the epoch (1970-01-01T00:00:00Z). num must be an integer type. unit may be one of the following: “second”, “millisecond”, “microsecond”, “nanosecond”.


curl https://db.fauna.com/ \
    -u kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE: \
    -d '{ "epoch": 0, "unit": "second" }'

client.query(Epoch(Value(0), TimeUnit.SECOND));

client.query(q.Epoch(0, "second"));

client.query(Epoch(0, "second"))

$client.query do
  epoch 0, 'second'
end

client.Query(Epoch(0, "second"));

client.query(q.epoch(0, "second"))

client.Query(f.Epoch(0, f.TimeUnitSecond))

client.query(Epoch(0, "second"))

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

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

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

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

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

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

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

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

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

date(str)

date constructs a date special type from an ISO 8601 date string.


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Miscellaneous Functions

next_id()

next_id produces a new identifier suitable for use when constructing refs.


curl https://db.fauna.com/ \
    -u kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE: \
    -d '{ "next_id": null }'

client.query(NextId());

client.query(q.NextId());

client.query(NextId())

$client.query do
  next_id 
end

client.Query(NextId());

client.query(q.next_id())

client.Query(f.NextId())

client.query(NextId())

HTTP/1.1 200 OK
{ "resource": "104979509699702175" }

=> "104979509699702175"

=> "104979509699702175"

=> "104979509699702175"

=> "104979509699702175"

=> "104979509699702175"

=> "104979509699702175"

=> "104979509699702175"

=> "104979509699702175"

database(db_name)

Given the name of a database, this function returns a valid ref that points to it. 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.


curl https://db.fauna.com/ \
    -u kqnPAi4gDivAAAC0i5t-a9YCcRnljtU2SfMJ-kWSRYI: \
    -d '{ "database": "prydain" }'

client.query(Database(Value("prydain")));

client.query(q.Database("prydain"));

client.query(Database("prydain"))

$client.query do
  database 'prydain'
end

client.Query(Database("prydain"));

client.query(q.database("prydain"))

client.Query(f.Database("prydain"))

client.query(Database("prydain"))

HTTP/1.1 200 OK
{ "resource": { "@ref": "databases/prydain" } }

=> { "@ref": "databases/prydain" }

=> { "@ref": "databases/prydain" }

=> { "@ref": "databases/prydain" }

=> { "@ref": "databases/prydain" }

=> { "@ref": "databases/prydain" }

=> { "@ref": "databases/prydain" }

=> { "@ref": "databases/prydain" }

=> { "@ref": "databases/prydain" }

class(class_name)

The class function returns a valid ref for the given class name


curl https://db.fauna.com/ \
    -u kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE: \
    -d '{ "class": "spells" }'

client.query(Class(Value("spells")));

client.query(q.Class("spells"));

client.query(Class("spells"))

$client.query do
  class_ 'spells'
end

client.Query(Class("spells"));

client.query(q.class_expr("spells"))

client.Query(f.Class("spells"))

client.query(Class("spells"))

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

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

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

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

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

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

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

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

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

index(index_name)

The index function returns a valid ref for the given index name


curl https://db.fauna.com/ \
    -u kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE: \
    -d '{ "index": "spells_by_element" }'

client.query(Index(Value("spells_by_element")));

client.query(q.Index("spells_by_element"));

client.query(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"))

client.Query(f.Index("spells_by_element"))

client.query(Index("spells_by_element"))

HTTP/1.1 200 OK
{ "resource": { "@ref": "indexes/spells_by_element" } }

=> { "@ref": "indexes/spells_by_element" }

=> { "@ref": "indexes/spells_by_element" }

=> { "@ref": "indexes/spells_by_element" }

=> { "@ref": "indexes/spells_by_element" }

=> { "@ref": "indexes/spells_by_element" }

=> { "@ref": "indexes/spells_by_element" }

=> { "@ref": "indexes/spells_by_element" }

=> { "@ref": "indexes/spells_by_element" }

function(function_name)

The function function returns a ref for the given function name


curl https://db.fauna.com/ \
    -u kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE: \
    -d '{ "function": "increment" }'

// Not available in this language yet.

// Not available in this language yet.

// Not available in this language yet.

# Not available in this language yet.

// Not available in this language yet.

# Not available in this language yet.

// Not available in this language yet.

// Not available in this language yet.

HTTP/1.1 200 OK
{ "resource": { "@ref": "functions/increment" } }

=> { "@ref": "functions/increment" }

=> { "@ref": "functions/increment" }

=> { "@ref": "functions/increment" }

=> { "@ref": "functions/increment" }

=> { "@ref": "functions/increment" }

=> { "@ref": "functions/increment" }

=> { "@ref": "functions/increment" }

=> { "@ref": "functions/increment" }

equals(val_1, val_2, ...)

equals tests equivalence between a list of values.


curl https://db.fauna.com/ \
    -u kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE: \
    -d '{ "equals": [ "fire", "fire" ] }'

client.query(Equals(Value("fire"), Value("fire")));

client.query(q.Equals("fire", "fire"));

client.query(Equals("fire", "fire"))

$client.query do
  equals 'fire', 'fire'
end

client.Query(EqualsFn("fire", "fire"));

client.query(q.equals("fire", "fire"))

client.Query(f.Equals("fire", "fire"))

client.query(Equals("fire", "fire"))

HTTP/1.1 200 OK
{ "resource": true }

=> true

=> true

=> true

=> true

=> true

=> true

=> true

=> true

contains(path, in)

contains returns true if the argument passed to in contains a value at the specified path, and false otherwise.


curl https://db.fauna.com/ \
    -u kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE: \
    -d '{
          "contains": [ "favorites", "foods" ],
          "in": {
            "object": {
              "favorites": {
                "object": { "foods": [ "crunchings", "munchings", "lunchings" ] }
              }
            }
          }
        }'

client.query(
  Contains(
    Arr(Value("favorites"), Value("foods")),
    Obj(
      "favorites", Obj(
        "foods", Arr(
          Value("crunchings"),
          Value("munchings"),
          Value("lunchings")
        )
      )
    )));

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

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

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

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(
    f.Contains(
        f.Arr{"favorites", "foods"},
        f.Obj{
            "favorites": f.Obj{
                "foods": f.Arr{"crunchings", "munchings", "lunchings"},
            },
        },
    ),
)

client.query(
    Contains(
        path: "favorites", "foods",
        in: Obj(
            "favorites" => Obj(
                "foods" => Arr("crunchings", "munchings", "lunchings")
            )
        )
    )
)

HTTP/1.1 200 OK
{ "resource": true }

=> true

=> true

=> true

=> true

=> true

=> true

=> true

=> true

select(path, from, [params])

select traverses into the argument passed to from and returns the resulting value. If the path does not exist, it results in an error.

Parameters
default Value optional Return this value instead of an error if the path does not exist.
all Boolean optional Flatten the selected value into an MVA. Useful for indexing.

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

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

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

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

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

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(
    f.Select(
        f.Arr{"favorites", "foods", 1},
        f.Obj{
            "favorites": f.Obj{
                "foods": f.Arr{"crunchings", "munchings", "lunchings"},
            },
        },
    ),
)

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

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

=> "munchings"

=> "munchings"

=> "munchings"

=> "munchings"

=> "munchings"

=> "munchings"

=> "munchings"

=> "munchings"

select allows you to extract class and id attributes from ref objects. Similarly, it allows extraction of ref, ts and class attributes from version objects


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

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

client.query(q.Select(["id"], q.Database("prydain")));

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

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

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

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

client.Query(f.Select(f.Arr{"id"}, f.Database("prydain")))

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

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

=> "prydain"

=> "prydain"

=> "prydain"

=> "prydain"

=> "prydain"

=> "prydain"

=> "prydain"

=> "prydain"

add(num_1, num_2, ...)

add computes the sum of a list of numbers. Attempting to add fewer that two numbers will result in an “invalid argument” error.


curl https://db.fauna.com/ \
    -u kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE: \
    -d '{ "add": [ 100, 10 ] }'

client.query(Add(Value(100), Value(10)));

client.query(q.Add(100, 10));

client.query(Add(100, 10))

$client.query do
  add 100, 10
end

client.Query(Add(100, 10));

client.query(q.add(100, 10))

client.Query(f.Add(100, 10))

client.query(Add(100, 10))

HTTP/1.1 200 OK
{ "resource": 110 }

=> 110

=> 110

=> 110

=> 110

=> 110

=> 110

=> 110

=> 110

multiply(num_1, num_2, ...)

multiply computes the product of a list of numbers. Attempting to multiply fewer than two numbers will result in an “invalid argument” error.


curl https://db.fauna.com/ \
    -u kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE: \
    -d '{ "multiply": [ 100, 10 ] }'

client.query(Multiply(Value(100), Value(10)));

client.query(q.Multiply(100, 10));

client.query(Multiply(100, 10))

$client.query do
  multiply 100, 10
end

client.Query(Multiply(100, 10));

client.query(q.multiply(100, 10))

client.Query(f.Multiply(100, 10))

client.query(Multiply(100, 10))

HTTP/1.1 200 OK
{ "resource": 1000 }

=> 1000

=> 1000

=> 1000

=> 1000

=> 1000

=> 1000

=> 1000

=> 1000

subtract(num_1, num_2, ...)

subtract computes the difference of a list of numbers. Attempting to subtract fewer than two numbers will result in an “invalid argument” error.


curl https://db.fauna.com/ \
    -u kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE: \
    -d '{ "subtract": [ 100, 10 ] }'

client.query(Subtract(Value(100), Value(10)));

client.query(q.Subtract(100, 10));

client.query(Subtract(100, 10))

$client.query do
  subtract 100, 10
end

client.Query(Subtract(100, 10));

client.query(q.subtract(100, 10))

client.Query(f.Subtract(100, 10))

client.query(Subtract(100, 10))

HTTP/1.1 200 OK
{ "resource": 90 }

=> 90

=> 90

=> 90

=> 90

=> 90

=> 90

=> 90

=> 90

divide(num_1, num_2, ...)

divide computes the quotient of a list of numbers, such that:


curl https://db.fauna.com/ \
    -u kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE: \
    -d '{ "divide": [ 10, 5, 2 ] }'

client.query(Divide(Value(10), Value(5), Value(2)));

client.query(q.Divide(10, 5, 2));

client.query(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))

client.Query(f.Divide(10, 5, 2))

client.query(Divide(10, 5, 2))

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

=> 1

=> 1

=> 1

=> 1

=> 1

=> 1

=> 1

=> 1

is equivalent to:


curl https://db.fauna.com/ \
    -u kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE: \
    -d '{ "divide": [ { "divide": [ 10, 5 ] }, 2 ] }'

client.query(Divide(Divide(Value(10), Value(5)), Value(2)));

client.query(q.Divide(q.Divide(10, 5), 2));

client.query(Divide(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))

client.Query(f.Divide(f.Divide(10, 5), 2))

client.query(Divide(Divide(10, 5), 2))

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

=> 1

=> 1

=> 1

=> 1

=> 1

=> 1

=> 1

=> 1

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.


curl https://db.fauna.com/ \
    -u kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE: \
    -d '{ "divide": [ 100, 10 ] }'

client.query(Divide(Value(100), Value(10)));

client.query(q.Divide(100, 10));

client.query(Divide(100, 10))

$client.query do
  divide 100, 10
end

client.Query(Divide(100, 10));

client.query(q.divide(100, 10))

client.Query(f.Divide(100, 10))

client.query(Divide(100, 10))

HTTP/1.1 200 OK
{ "resource": 10 }

=> 10

=> 10

=> 10

=> 10

=> 10

=> 10

=> 10

=> 10

modulo(num_1, num_2, ...)

modulo computes the remainder after division of a list of numbers, such that:


curl https://db.fauna.com/ \
    -u kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE: \
    -d '{ "modulo": [ 10, 5, 2 ] }'

client.query(Modulo(Value(10), Value(5), Value(2)));

client.query(q.Modulo(10, 5, 2));

client.query(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))

client.Query(f.Modulo(10, 5, 2))

client.query(Modulo(10, 5, 2))

HTTP/1.1 200 OK
{ "resource": 0 }

=> 0

=> 0

=> 0

=> 0

=> 0

=> 0

=> 0

=> 0

is equivalent to:


curl https://db.fauna.com/ \
    -u kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE: \
    -d '{ "modulo": [ { "modulo": [ 10, 5 ] }, 2 ] }'

client.query(Modulo(Modulo(Value(10), Value(5)), Value(2)));

client.query(q.Modulo(q.Modulo(10, 5), 2));

client.query(Modulo(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))

client.Query(f.Modulo(f.Modulo(10, 5), 2))

client.query(Modulo(Modulo(10, 5), 2))

HTTP/1.1 200 OK
{ "resource": 0 }

=> 0

=> 0

=> 0

=> 0

=> 0

=> 0

=> 0

=> 0

Attempting to call modulo with an empty array will result in an “invalid argument” error.

Attempting to compute the remainder of a division by zero will result in a “invalid argument” error.


curl https://db.fauna.com/ \
    -u kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE: \
    -d '{ "modulo": [ 100, 11 ] }'

client.query(Modulo(Value(100), Value(11)));

client.query(q.Modulo(100, 11));

client.query(Modulo(100, 11))

$client.query do
  modulo 100, 11
end

client.Query(Modulo(100, 11));

client.query(q.modulo(100, 11))

client.Query(f.Modulo(100, 11))

client.query(Modulo(100, 11))

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

=> 1

=> 1

=> 1

=> 1

=> 1

=> 1

=> 1

=> 1

lt(value_1, value_2, ...)

lt returns true if each specified value compares as 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.


curl https://db.fauna.com/ \
    -u kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE: \
    -d '{ "lt": [ 1, 2, 3 ] }'

client.query(LT(Value(1), Value(2), Value(3)));

client.query(q.LT(1, 2, 3));

client.query(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))

client.Query(f.LT(1, 2, 3))

client.query(LT(1, 2, 3))

HTTP/1.1 200 OK
{ "resource": true }

=> true

=> true

=> true

=> true

=> true

=> true

=> true

=> true

lte(value_1, value_2, ...)

lte returns true if each specified value compares as 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.


curl https://db.fauna.com/ \
    -u kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE: \
    -d '{ "lte": [ 1, 2, 2 ] }'

client.query(LTE(Value(1), Value(2), Value(2)));

client.query(q.LTE(1, 2, 2));

client.query(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))

client.Query(f.LTE(1, 2, 2))

client.query(LTE(1, 2, 2))

HTTP/1.1 200 OK
{ "resource": true }

=> true

=> true

=> true

=> true

=> true

=> true

=> true

=> true

gt(value_1, value_2, ...)

gt returns true if each specified value compares as 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.


curl https://db.fauna.com/ \
    -u kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE: \
    -d '{ "gt": [ 3, 2, 1 ] }'

client.query(GT(Value(3), Value(2), Value(1)));

client.query(q.GT(3, 2, 1));

client.query(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))

client.Query(f.GT(3, 2, 1))

client.query(GT(3, 2, 1))

HTTP/1.1 200 OK
{ "resource": true }

=> true

=> true

=> true

=> true

=> true

=> true

=> true

=> true

gte(value_1, value_2, ...)

gte returns true if each specified value compares as 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.


curl https://db.fauna.com/ \
    -u kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE: \
    -d '{ "gte": [ 3, 2, 2 ] }'

client.query(GTE(Value(3), Value(2), Value(2)));

client.query(q.GTE(3, 2, 2));

client.query(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))

client.Query(f.GTE(3, 2, 2))

client.query(GTE(3, 2, 2))

HTTP/1.1 200 OK
{ "resource": true }

=> true

=> true

=> true

=> true

=> true

=> true

=> true

=> true

and(bool_1, bool_2, ...)

and computes the conjunction of a list of boolean values, returning true if all elements are true, and false otherwise.


curl https://db.fauna.com/ \
    -u kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE: \
    -d '{ "and": [ true, true, false ] }'

client.query(And(Value(true), Value(true), Value(false)));

client.query(q.And(true, true, false));

client.query(And(true, true, false))

$client.query do
  and_ true, true, false
end

client.Query(And(true, true, false));

client.query(q.and_expr(True, True, False))

client.Query(f.And(true, true, false))

client.query(And(true, true, false))

HTTP/1.1 200 OK
{ "resource": false }

=> false

=> false

=> false

=> false

=> false

=> false

=> false

=> false

or(bool_1, bool_2, ...)

or computes the disjunction of a list of boolean values, returning true if any elements are true, and false otherwise.


curl https://db.fauna.com/ \
    -u kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE: \
    -d '{ "or": [ true, true, false ] }'

client.query(Or(Value(true), Value(true), Value(false)));

client.query(q.Or(true, true, false));

client.query(Or(true, true, false))

$client.query do
  or_ true, true, false
end

client.Query(Or(true, true, false));

client.query(q.or_expr(True, True, False))

client.Query(f.Or(true, true, false))

client.query(Or(true, true, false))

HTTP/1.1 200 OK
{ "resource": true }

=> true

=> true

=> true

=> true

=> true

=> true

=> true

=> true

not(bool)

not computes the negation of a boolean value, returning true if its argument is false, or false if its argument is true.


curl https://db.fauna.com/ \
    -u kqnPAi3Kj3ZgAAC0Hu51Ng2dtn0JcgP7Fb-Q_uzLGZE: \
    -d '{ "not": true }'

client.query(Not(Value(true)));

client.query(q.Not(true));

client.query(Not(true))

$client.query do
  not_ true
end

client.Query(Not(true));

client.query(q.not_expr(True))

client.Query(f.Not(true))

client.query(Not(true))

HTTP/1.1 200 OK
{ "resource": false }

=> false

=> false

=> false

=> false

=> false

=> false

=> false

=> false