Vercel Logo
DOCS
DEVELOPER GUIDELINE
CONDITIONAL BRANCHING

If-Else Pipeline

In the realm of Syncraft, the If-Else Pipeline acts as a decision-maker, orchestrating the flow of logic based on certain conditions. This pipeline is paramount when the data processing logic needs to diverge based on specific predicates.

Core Components:

The If-Else Pipeline is structured around three primary components:

  1. Condition: A predicate query that dictates the course of action.
  2. Then: The pipeline to be executed if the condition holds true.
  3. Else: The pipeline to be executed if the condition holds false.
Try In Playground
[ { "query": { "id": { "eq": 2 } }, "selection": { "id": true, "name": true }, "root": "Users" }, { "if": { "id": { "eq": 21 } }, "then": { "query": { "id": { "eq": 4 } }, "selection": { "id": true, "name": true }, "root": "Users" }, "else": { "query": { "id": { "eq": 1 } }, "selection": { "id": true, "name": true, "active": true }, "root": "Users" } } ]

Workflow:

  1. Condition Evaluation: The if block contains the condition to be evaluated. In the example above, it checks if the id field equals 21.
  2. Then Execution: If the condition is true, the then block is executed. Here, it queries for a user with id equal to 4 and selects the id and name fields from the Users root.
  3. Else Execution: If the condition is false, the else block is executed. In this scenario, it queries for a user with id equal to 1 and selects the id, name, and active fields from the Users root.

Integration:

The If-Else Pipeline can seamlessly blend within a larger query pipeline structure, facilitating condition-driven logic flows. It can be nested within higher-order pipelines like Serial, Parallel, or Race pipelines to further fine-tune the logic flow, making the query engine versatile and adaptive to varying data scenarios.

Learn More
Filters and Data Guards
Continue Your Journey
Looping Pipelines