Nodes/comfyui-tensorop/SaveTextToSurreal
ComfyUI Node

SaveTextToSurreal

The SurrealDB text node with a quote problem you should know about

By un-seen·Created 2 years ago·Updated 2 years ago· 46
SaveTextToSurreal
      database
      text
      id
      key

      SaveTextToSurreal is the plain-text sibling of SaveJsonToSurreal, and it exists because half the things you want to persist next to a generation are just strings - a prompt, a caption, a filename, a note. It writes one string value into SurrealDB under a field you name, on a record you choose by id. Simple idea, and mostly a simple node. But it has one sharp edge that will cost you an hour if nobody warns you: it does not escape the text it stores.

      How it works

      It connects to SurrealDB using the credentials in the pack's config.py (URL, namespace, user, password) and the database input you set on the node. Then it upserts onto a hardcoded table called processor:

      UPDATE processor:`id` CONTENT {key: 'text'}
      

      The id input picks the record, the key input names the field, and the text input is your value. Run it twice with the same id and the field updates in place. Like the JSON version, the table name is baked into the source (SURREAL_TABLE = "processor") - you can't change it from the UI.

      Where people get burned: the quoting

      Look at that query again. The text goes into the statement wrapped in single quotes, with no escaping anywhere in the chain. So the moment your text contains an apostrophe - "don't", "it's", any contraction - the string terminates early and you get a malformed query. The classic demo: you log a user's "don't like this" note and the write fails or corrupts.

      That's not hypothetical pedantry; the value is interpolated straight into the SurrealQL statement. A stray ' in your text doesn't just break that one write, it changes what the query means. In a workflow, "text" usually comes from a prompt or a caption field, which is exactly where apostrophes live. Before you wire this into anything, sanitize or accept that plain strings with quotes are a trap.

      The fix is boring but real: for anything with punctuation, prefer the pack's SaveJsonToSurreal and send a JSON string instead. JSON's own escaping handles quotes properly. Reserve this node for short, clean, plain-text values - tags, IDs, labels.

      The inputs

      • database - which SurrealDB database to connect to.
      • id - the record id to upsert onto.
      • key - the field name.
      • text - the STRING value. Note the input is declared with forceInput, so you can wire it straight from any text-producing node instead of typing.

      No outputs - output node, terminates the branch.

      Install and config

      The repo ships no real README, so it's the standard path: ComfyUI Manager, search the pack title comfyui-tensorop, or:

      cd ComfyUI/custom_nodes
      git clone https://github.com/un-seen/comfyui-tensorops
      

      then restart. The pack's requirements.txt is heavy (boto3, redis, surrealist, fal-client, replicate, scipy) and it all lands in your shared ComfyUI Python environment - there's no slim install for just the SurrealDB nodes.

      Then edit nodes/config.py - empty-string defaults, no env vars:

      SURREAL_URL = "http://localhost:8000"
      SURREAL_NAMESPACE = "your-namespace"
      SURREAL_USER = "root"
      SURREAL_PASSWORD = "your-password"
      

      Restart after editing. A SurrealDB server needs to be up and reachable, because the node connects fresh on every execution with a 10-second timeout.

      The rest of the gotchas

      • Dead server, silent-ish failure. If SurrealDB is down or the database doesn't exist, the write fails at the query step. Check the ComfyUI console - this pack tends to log rather than raise.
      • Hardcoded processor table, same as its JSON sibling. Different table means editing nodes/save_surreal.py.
      • This is a personal-pack node. comfyui-tensorops is a single commit from October 2024, and its one community moment was ComfyUI Manager flagging it for node-name conflicts with Kijai's Florence2 pack. MIT-licensed and quiet since. Install it because you have a concrete SurrealDB pipeline, not for kicks - and skim the source while you're at it.
      Categorydatabase_ops

      Inputs (4)

      NameTypeDefaultDescription
      databaseSTRING
      textSTRING
      idSTRING
      keySTRING

      Outputs (0)

      No outputs