Given rows declaration

A given stage preceding a query indicates the pipeline expects input "rows" to be provided along when the query is executed. It declares a number of input variables, and the expected type of each variable. If the value provided for a given variable does not match the declared type, an execution error is returned.

For examples on how to pass the given rows for a query, check the driver documentation ( GRPC / HTTP API )

Syntax

given <var>: <type> [, <var>: <type>, ... ];

Example

Schema for the following examples
#!test[schema, commit]
define
  entity content owns id;
  entity page sub content,
    owns page-id,
    owns name;
  entity profile sub page,
    owns username;
  entity user sub profile,
    owns phone,
    owns karma;

  attribute id value string;
  attribute page-id sub id;
  attribute username sub page-id;
  attribute name value string;
  attribute phone value string;
  attribute karma value double;
attribute start-date, value date;
relation friendship relates friend @card(0..2), owns start-date;
user plays friendship:friend;

Given rows can be values…​

#!test[write, given=name]
given $name: string;
insert $u isa user, has username == $name;

or concepts (returned by previous queries).

#!test[write, given=u1;u2]
given $u1: user, $u2: user;
insert $_ isa friendship, links (friend: $u1, friend: $u2);

Given variables can be optional, allowing for conditional inserts:

#!test[write, given=uname;name;phone]
given $uname: username, $name: string, $phone: string?;
match $u isa user, has $uname;
insert
    $u has name == $name;
    try { $u has phone == $phone; };