paracelsus icon indicating copy to clipboard operation
paracelsus copied to clipboard

Question: Using paracelsus with SQLAlchemy core

Open berislavlopac opened this issue 7 months ago • 2 comments

I would like to inquire it would be possible to use Paracelsus with the SQLAlchemy core-based configurations, using the Table definitions instead of ORM.

To be more precise, I know that it can: since Paracelsus looks for the .metadata attribute on a Base class, I got the expected result from a configuration like this:

import sqlalchemy as sa

meta = sa.MetaData()

class Base:
    metadata = meta

test_table = sa.Table(
    "test_table",
    meta,
    sa.Column("id", sa.UUID, primary_key=True),
    sa.Column("name", sa.String(256)),
)
$ paracelsus graph database.tables:Base
erDiagram
  test_table {
    UUID id PK
    VARCHAR(256) name "nullable"
  }

It would be nice if we could have a CLI argument that would point to the metadata directly, i.e. something like paracelsus graph --meta database.tables:meta in the example above. Or even it can be automated by checking if the indicated object is already a MetaData instance before reverting to the original behaviour. 🤔

Any thoughts?

berislavlopac avatar May 06 '25 09:05 berislavlopac

I think this is a great idea, and have labelled the ticket to try and attract someone to take a look at this. If no one else picks it up I'll probably tackle it in a few weeks, as I have some conferences I'm speaking at and need to buckle down and actually write the talks.

tedivm avatar May 09 '25 21:05 tedivm

Thanks for this!

I was using SQLModel and this was the hint I needed.

I ended up with the following:

models.py

from sqlmodel import SQLModel

#...
#my models
#...

metadata = SQLModel.metadata

erd.py

from models import metadata


class Base:
    metadata = metadata

pyproject.toml


[tool.paracelsus]
base = "erd:Base"
imports = []
exclude_tables = []
column_sort = "preserve-order"
omit_comments = false

mattmalcher avatar Aug 26 '25 15:08 mattmalcher