Skip to main content

Query

Uncontrolled node

Overview

The Query node generates SQL query strings using Handlebars templating syntax. It allows you to write SQL templates that incorporate dynamic values from your workflow, such as variables, inputs, or data from other nodes. The node compiles the template at runtime, substituting variables with actual values, and outputs the resulting SQL string.

This node is particularly useful for constructing dynamic database queries where table names, column names, or filter values need to be parameterized based on runtime data.

Template Syntax

The Query node uses Handlebars syntax ({{variableName}}) for variable substitution. Any variables referenced in double curly braces within your SQL template will automatically appear as inputs to the node.

For example, if your query contains SELECT * FROM {{tableName}} WHERE id = {{userId}}, the node will dynamically create inputs for tableName and userId.

Inputs

InputTypeDescriptionDefault
QueryCodeThe SQL query template using Handlebars syntax. Supports standard SQL with variable placeholders like {{variableName}}.-
DynamicDataAny Handlebars variables referenced in the query template appear as additional inputs. These are automatically generated based on the template content.-

Outputs

OutputTypeDescription
OutputTextThe compiled SQL query string with all Handlebars variables substituted with their actual values.

Runtime Behavior and Defaults

The Query node is uncontrolled, meaning it executes automatically whenever any of its inputs change. It does not require an event trigger to run.

When the node runs:

  1. It retrieves the SQL template from the query property
  2. It collects values from all dynamic inputs (Handlebars variables detected in the template)
  3. It compiles the Handlebars template using the current variable values from the workflow scope, parent scope, and node inputs
  4. It outputs the resulting SQL string

If the query template is empty, the node outputs an empty string.

Example

Basic Usage

Query Template:

SELECT * FROM users WHERE status = '{{status}}' AND created_at > '{{startDate}}'

Inputs:

  • status: "active"
  • startDate: "2024-01-01"

Output:

SELECT * FROM users WHERE status = 'active' AND created_at > '2024-01-01'

Dynamic Table Names

Query Template:

SELECT {{columns}} FROM {{tableName}} WHERE id = {{recordId}}

Inputs:

  • tableName: "customers"
  • columns: "name, email, phone"
  • recordId: 12345

Output:

SELECT name, email, phone FROM customers WHERE id = 12345

Usage with Database Nodes

Connect the Query node's output to the query input of a QueryDatabase node to execute the generated SQL against your project database:

[Query Node] → [QueryDatabase Node]
(SQL) (execution)