DRAFTThis page is not published. Only visible in development mode.

Control Flow

RQL statements can bind variables, branch, loop, and define functions - queries become scripts without leaving the language or the transaction. Every construct runs inside the same atomic request as the queries around it. This page is the map; each construct has its own page with runnable examples.

The constructs

Everything here builds on variables - let bindings hold the values that conditions test and loops accumulate. Start there if you have not.

  • --Conditionals - if / else if / else as statements that guard writes and as expressions that produce values.
  • --Match - multi-way branching on a value or on conditions, and the idiom for defaulting missing values.
  • --For loops - iterate a numeric range or the rows of a captured query result.
  • --While loops - repeat while a condition holds, with a built-in runaway guard.
  • --Loop, break & continue - explicit loops that exit with break and skip with continue.
  • --Closures & functions - anonymous closures that capture their scope, and named udf functions callable inside pipelines.

One request, one transaction

A script is still a single request: every statement it contains - loops that insert, branches that update - commits atomically or not at all, with the same guarantees as any other request. See Transactions. For reusable logic that lives in the database rather than in a script, see Procedures.

Scripts are not a general-purpose language
Control flow exists to orchestrate data work - conditional writes, batch setup, migrations - not to replace application code. If a computation does not read or write the database, it belongs in your application, next to the client that calls ReifyDB.