Skip to Content

next-workflow-builder

DevKit AI Builder Template DocumentationMarketplace
CTRL K
Demo
CTRL K
  • DevKit 
  • AI Builder Template 
    • Introduction
    • Getting Started
    • Configuration
    • Plugins
      • Overview
      • HTTP Request
      • Condition
      • Loop
      • Merge
      • Database Query
      • Run Workflow
      • Run Workflows in Sequence
      • Switch
    • Creating Plugins
    • API Reference
    • CLI Reference
    • Components
    • Database
    • Authentication
    • Deployment
    • Architecture
    • Contributing
    • MCP Server
  • Marketplace
  • Introduction
  • Getting Started
  • Configuration
  • Plugins
    • Overview
    • HTTP Request
    • Condition
    • Loop
    • Merge
    • Database Query
    • Run Workflow
    • Run Workflows in Sequence
    • Switch
  • Creating Plugins
  • API Reference
  • CLI Reference
  • Components
  • Database
  • Authentication
  • Deployment
  • Architecture
  • Contributing
  • MCP Server

On This Page

  • Configuration
  • Output
  • Usage Examples
  • Simple SELECT query
  • Query with template references
  • INSERT with returning
  • Connection
  • Error Handling
  • Generated Code
Question? Give us feedback Edit this page 
DocumentationBuilt-in PluginsDatabase Query

Database Query

Execute SQL queries against a PostgreSQL database. This plugin connects to your database using a configured connection string and returns query results.

Configuration

FieldTypeRequiredDescription
SQL QueryCode Editor (SQL)YesThe SQL query to execute. Supports template references
ConnectionIntegration SelectorNoDatabase integration to use. Falls back to DATABASE_URL environment variable

Output

FieldTypeDescription
successbooleanWhether the query executed successfully
rowsunknown[]Array of result rows
countnumberNumber of rows returned
errorstringError message if success is false

Usage Examples

Simple SELECT query

SELECT * FROM users WHERE active = true ORDER BY created_at DESC LIMIT 100

Query with template references

Use data from a previous node in your query:

SELECT * FROM orders WHERE user_id = '{{Trigger.userId}}'

INSERT with returning

INSERT INTO logs (event, data, created_at) VALUES ('workflow_run', '{{HTTPRequest.data}}', NOW()) RETURNING id

Connection

The Database Query plugin resolves its database connection in this order:

  1. Integration selector — If a database integration is selected, the plugin fetches the DATABASE_URL from the stored (encrypted) credentials
  2. Environment variable — Falls back to the DATABASE_URL environment variable

The connection uses:

  • Max 1 connection per query
  • 10-second connect timeout
  • 20-second idle timeout
  • Automatic cleanup after query completion

Error Handling

Common error scenarios and their messages:

ErrorCause
Connection refusedDatabase server is not running or not accessible
Host not foundInvalid hostname in connection string
Authentication failedWrong username or password
Relation does not existTable or view not found
Syntax errorInvalid SQL syntax

Generated Code

When exporting a workflow, the Database Query action generates:

import { databaseQueryStep } from './steps/database-query-step'; const result = await databaseQueryStep({ dataSource: { name: "my-database" }, query: `SELECT * FROM users WHERE active = true`, });
Last updated on March 12, 2026
MergeRun Workflow

© 2026 All rights reserved.

Product by David Sanchez