Let
Let( bindings, in )
Let( bindings, in )
Let( bindings, in )
Let( bindings, in )
let( bindings, in )
Let( bindings, in )
Description
The Let
function binds one or more variables to a single value or
expression. When multiple variables are defined, the evaluation is from
left to right. Variables which have previously been defined may be used
to define future variables. Variables are lexically scoped to the
expression passed via the in
parameter. The value of a variable can be
referenced with Var(varname)
syntax.
Parameters
Argument | Type | Definition and Requirements |
---|---|---|
|
List of pairs |
The variable or variables to define. |
|
Expression |
The expression in which the variables are defined. |
Examples
The query below defines two variables to be used by the expression
defined by the in
argument. The first variable "x" contains the value
1 and the second variable "y" contains the value 2. The expression
defined by the in
argument simply returns the value of the variable
"x". The value is accessed by using the Var
statement with the associated variable’s name.
Value result = await client.Query(
Let("x", 1, "y", 2).In(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!