Skip to content

db_query

Parameterized SQL query against a configured DSN.

Sourceinternal/agents/workflow/nodes/db_query.go
When to useReading from an external user database — Postgres, SQLite.
Supported driverspostgres://, sqlite:, file:

Schema

FieldTypeRequiredNotes
databasestringEnv key whose value is the DSN. Stored in the workflow's env: block.
querytextarea (template)SQL with $1 / $2 / … placeholders (Postgres style — sqlite driver normalises).
paramslist (templated)Positional params for the placeholders. Each value rendered as a Go template.
timeout_secintPer-call timeout.

Output

FieldTypeWhat
rows[]map[string]anyOne entry per row, column name → cell value.
row_countintSame as len(rows).
columns[]stringColumn names in order.

Example

json
{
  "env": [
    {"key": "USERS_DB", "desc": "Read-only DSN to the users database", "secret": true}
  ],
  "graph": {
    "nodes": [
      {
        "id": "lookup_user",
        "type": "db_query",
        "database": "USERS_DB",
        "query": "SELECT id, email, plan, created_at\nFROM users\nWHERE id = $1",
        "params": ["{{index .Event.Payload \"user_id\"}}"]
      }
    ]
  }
}

Downstream nodes reach {{index (index .Node.lookup_user.rows 0) "plan"}} (or {{.Node.lookup_user.row_count}} for a quick existence check).

Read-only, by convention

The connector framework's OpDestructive annotation has no analogue here — wick doesn't parse the SQL. Use a read-only DSN when wiring up the env var; if you genuinely need writes, scope the credential and confirm it's intentional.

Pair with

  • branch — route on row_count for "found vs not found" flows.
  • transform — reshape rows before downstream nodes.
Built with ❤️ by a developer, for developers.