Skip to main content

Query

Queries provide a controlled way to retrieve data in Rell.

Queries have the following characteristics:

  • Can't modify the data in the database (compile-time verification)
  • Must return a value
  • If the return type isn't explicitly specified, it's implicitly deducted
  • Parameter types and return types must be GTV-compatible

Short form

Compact syntax for straightforward queries:

query q(x: integer): integer = x * x;

Full form

More explicit syntax with a return statement:

query q(x: integer): integer {
return x * x;
}

Default parameter values

Queries can have parameters with default values, making them optional when called from the blockchain (external clients). This allows you to add new parameters without breaking existing client code.

query get_users(min_age: integer = 0, max_age: integer = 100): list<user> {
return user @* { .age >= min_age, .age <= max_age };
}

In this example, both min_age and max_age have default values, so they're optional when calling the query from the blockchain. Clients can call get_users without any parameters, with just min_age, or with both parameters.