Read DB → Dataset
Read DB → Dataset is SQLite-only, and that's fine — SQLAlchemy is already in your ComfyUI env
- dataset
What it is
ComfyDL - Cynthia-lxx's pack for running d2l-style deep learning inside ComfyUI - centres on a universal DATASET type: a feature tensor, optional labels, column names, passed by reference between nodes. Read DB → Dataset reads one by running SQL: you point it at a SQLite file, paste a query, and get a dataset back.
That's a better deal than it sounds. SQL is the one data-prep tool that scales past "my CSV has a weird row 47" - WHERE, joins, GROUP BY, computed columns, LIMIT for a quick subset. Doing the shaping in the query means the tensors you get are already the ones you want, and you can iterate on the query without touching the database.
How it works
The node builds a SQLAlchemy engine from an f-string - create_engine(f"sqlite:///{db_path}") - opens a connection, and runs pd.read_sql_query(text(query), conn). That text() wrapper is the SQLAlchemy 2.x idiom; the code is written for the modern API, and SQLAlchemy arrives with ComfyUI itself rather than with this pack, so you rarely have to install anything.
Then it's the same conversion as every other reader: CdlDataset.from_dataframe pops the target column off as labels, casts the rest to float32/float64 via torch.from_numpy, and keeps column names.
It's SQLite only. The connection URL is hard-coded to sqlite:///, and there's no field for a connection string or a driver. Postgres, MySQL, DuckDB, SQL Server - not this node. Export to SQLite first, or to CSV.
Inputs and outputs
Required: db_path (default cdl_dataset.db), query (multiline, default SELECT * FROM data - the same table name the pack's DB writer defaults to), and target (label column, empty for unlabelled). Optional: dtype.
Output: one dataset. The natural chain is Read DB → Dataset → Dataset → Preview → Dataset → Tensors → Linear Regression Train. And since queries are just strings, you can wire a text node into the query socket if you want to build SQL from a prompt or a graph value.
Install
Manager → search ComfyDL, or by hand:
cd ComfyUI/custom_nodes
git clone https://github.com/Cynthia-lxx/ComfyDL
pip install -r ./ComfyDL/requirements.txt
Restart ComfyUI. The pack's requirements are only matplotlib, IPython and matplotlib-inline - pandas and SQLAlchemy both come from your existing environment. If ComfyDL nodes simply aren't in the menu, check the console for [ComfyDL] Warning: Failed to load <module>: the pack imports each module in a try/except, so a missing dependency reads as a missing node.
Where people get burned
The path in a SQLAlchemy URL is not a plain path. sqlite:///relative.db is relative to ComfyUI's working directory; on Windows, a drive letter inside the URL needs forward slashes (sqlite:///D:/data/x.db), and backslashes will hand you an unhelpful connection error. The safest habit is to pass the absolute path with forward slashes.
Only one statement. pd.read_sql_query runs a query. CREATE, INSERT, ATTACH, multiple statements separated by semicolons - not this node. Use the pack's Dataset → Write DB for writing, and a SQL tool for schema work.
SELECT * picks up everything. Every non-target column becomes a float feature, so a text column (a name, a timestamp, a UUID) breaks the conversion. Name your columns in the query: SELECT x1, x2, y FROM data.
A missing table or column comes back as SQLAlchemy's OperationalError: no such table - usually a typo, or a path that silently created a fresh empty database. Note that ComfyUI is happy to make a new empty .db when the path resolves somewhere writable: if your query fails on a table that definitely exists, check the path first.
An empty query result gives you a zero-row dataset, not an error - the failure shows up later as a shape mismatch when you try to train.
It loads the whole result set. No chunking, so use LIMIT while you're iterating, and only run the full thing once the query is right.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| db_path | STRING | cdl_dataset.db | — |
| query | STRING | SELECT * FROM data | — |
| target | STRING | — | |
| dtypeopt | COMBO | float32 | 2 options: float32, float64 |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| dataset | DATASET | — |