Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

db_write

The raw-SQL escape hatch for writes (multi-table statements, UPDATE … FROM, SQL functions in SET, DDL). Runs an INSERT/UPDATE/DELETE against a SQL connector and writes { "rows_affected": N }. Note: the author writes dialect-specific SQL, and a connector can disable this function entirely through its raw_write operation gate.

Synopsis

{
  "name": "db_write",
  "input": {
    "connector": "primary-db",
    "query": "INSERT INTO orders (id, total) VALUES (?, ?)",
    "params": [
      {
        "var": "data.order.id"
      },
      {
        "var": "data.order.total"
      }
    ],
    "output": "data.write_result"
  }
}

Description

db_write is a connector function. It names a connector for its credentials and endpoint. Orion validates its input when the workflow is saved, and the call runs through the connector’s circuit breaker.

Retry safety: depends_on sql. See Retry safety for what the answer costs.

An INSERT also carries last_insert_id on MySQL and SQLite, the same key data_write reports. PostgreSQL does not report one; it uses RETURNING, which the portable dialect supports. The key appears for an INSERT/REPLACE only. SQLite’s last_insert_rowid belongs to the connection, so after an UPDATE it would report whatever an earlier insert on that pooled connection left behind.

Fields

FieldTypeRequiredDefaultDescription
connectorstringyesName of the SQL connector
querystringyesINSERT/UPDATE/DELETE statement with bind placeholders
paramsarraynoValues bound to the placeholders, in order. Each element folds {"var": …} and nothing else — an operator written inline binds as a literal object, which lint reports as logic.unresolvable; compute it in a map task first
outputstring | JSONLogicno"data"Dotted path where { "rows_affected": N } (plus last_insert_id after an insert) is written

Examples

{
  "name": "db_write",
  "input": {
    "connector": "primary-db",
    "query": "INSERT INTO orders (id, total) VALUES (?, ?)",
    "params": [{ "var": "data.order.id" }, { "var": "data.order.total" }],
    "output": "data.write_result"
  }
}

Last verified 14 September 2026