Var

Var( name )
Var( name )
Var( name )
Var( name )
let name
Var (  name )

Description

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

Parameters

Argument Type Definition and Requirements

name

String

The name of the variable.

Returns

The value stored in the named variable.

Examples

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

client.Query(Let(Obj("x", 1, "y", 2), Var("x")));
1
curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "let": { "x": 1, "y": 2 }, "in": { "var": "x" } }'
HTTP/1.1 200 OK
{ "resource": 1 }
result, _ := client.Query(f.Let(f.Obj{"x": 1, "y": 2}, f.Var("x")))

fmt.Println(result)
1
System.out.println(
         client.query(
               Let( "x", Value(1), "y", Value(2) ).in( Var("x") )
         ).get() );
1
client.query(
  q.Let({ x: 1, y: 2 }, q.Var('x'))
)
.then((ret) => console.log(ret))
1
client.query(q.let({"x": 1, "y": 2}, q.var("x")))
1
Let(Seq("x" -> 1, "y" -> 2), Var("x"))
1

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!