ComfyUI Node

DB Get Item

Pull any value out of a loaded data file, one expression at a time

By hanoixan·Created 2 years ago·Updated 2 years ago· 2
DB Get Item
  • source
  • value
expression

DBGetItem is how you actually get at the data once DBLoadData has slurped a file into a DB_ITEM. The loader hands you one giant opaque dictionary; this node digs a value out of it using Python bracket notation and hands it back as a string. If you've used JSON-path or jq-style tools, the mental model is the same, just written like Python list/dict indexing.

How it works

The node appends your expression text onto the loaded data and evaluates it with RestrictedPython - the same sandboxed eval() the whole pack uses, restricted to plain indexing plus the passed-in value. So if a DBLoadData has loaded a document where defs is a dict and color_list is a list, an expression of ['defs']['color_list'][23] resolves to the value at that spot. Note that the source doesn't have to come straight from the loader: the tooltip says it can come from DBLoadData, DBGetItem, or DBGetBatchList, and chaining them is a clean way to drill into nested structures.

Inputs and output

  • source - the DB_ITEM you're querying.
  • expression - the bracket-notation path, e.g. ['foo'][1] to grab the second element of the foo key, or ['items'][0] for the first row of a CSV-loaded file.

The single output, value, is itself a DB_ITEM. The important quirk: it's always a string. The node stringifies whatever it finds before wrapping it back up. That's by design - the README calls the whole DBGet* family "string" accessors, and it's exactly why the DBConvertToInt / DBConvertToFloat / DBConvertToBoolean / DBConvertToString nodes exist downstream. Want a real float for a CFG widget? DBGetItemDBConvertToFloat. Want a prompt text? DBGetItemDBConvertToString.

What to watch for

The most common beginner stumble is writing the expression as Python you'd type at a REPL (defs['color_list'][23]) instead of the bracket-notation the node expects (['defs']['color_list'][23]). The node prepends source_item, so your expression is literally the indexing suffix - quote every key, every time.

Like the rest of this pack, errors fail quiet: an expression that doesn't resolve gets swallowed and you end up with the string None or empty output rather than an error popping up in the UI. When in doubt, test the expression in Python against your actual data first. And remember you're on your own for examples - the pack has essentially none floating around, so the bracket syntax in the README and this node's tooltip are the real docs.

Installing

DB Get Item ships in ComfyUI DataBeast. The pack isn't in ComfyUI Manager yet, so:

cd ComfyUI/custom_nodes
git clone https://github.com/hanoixan/ComfyUI-DataBeast
cd ComfyUI-DataBeast
pip install -r requirements.txt

Restart ComfyUI and you'll find all the DB nodes under the DataBeast category. Dependencies are just pyyaml and RestrictedPython - no models, no downloads.

CategoryDataBeast

Inputs (2)

NameTypeDefaultDescription
sourceDB_ITEMSource item to query.
expressionSTRINGThe expression to apply to the source, if necessary. Ex: To get the 2nd index of the key "foo" assuming the source is a table, the expression is: ["foo"][1]

Outputs (1)

NameTypeDescription
valueDB_ITEM