Getting field metadata for use in autogenerated model diagrams (erdantic) #1933
Replies: 11 comments
-
|
Here is the mappingproxy({'Config': <class 'geo_info_svg.models.Country.Config'>,
'__abstractmethods__': frozenset(),
'__annotations__': {'geometry': <class 'geoalchemy2.types.Geometry'>,
'id': typing.Optional[int],
'name': <class 'str'>,
'population': <class 'int'>},
'__class_vars__': {'__name__',
'__sqlmodel_relationships__',
'__tablename__',
'metadata'},
'__config__': <class 'sqlmodel.main.Config'>,
'__custom_root_type__': False,
'__doc__': None,
'__exclude_fields__': None,
'__fields__': {'geometry': ModelField(name='geometry', type=Geometry, required=True),
'id': ModelField(name='id', type=Optional[int], required=False, default=None),
'name': ModelField(name='name', type=str, required=True),
'population': ModelField(name='population', type=int, required=True)},
'__hash__': None,
'__include_fields__': None,
'__init__': <function __init__ at 0x7f236f753370>,
'__json_encoder__': <staticmethod(<cyfunction pydantic_encoder at 0x7f237d1bae90>)>,
'__mapper__': <Mapper at 0x7f236f74a320; Country>,
'__module__': 'geo_info_svg.models',
'__post_root_validators__': [],
'__pre_root_validators__': [],
'__private_attributes__': {},
'__schema_cache__': {},
'__signature__': <pydantic.utils.ClassAttribute object at 0x7f236f749e70>,
'__slots__': set(),
'__sqlmodel_relationships__': {},
'__table__': Table('country', MetaData(), Column('geometry', Geometry(geometry_type='POLYGON', srid=3035, from_text='ST_GeomFromEWKT', name='geometry'), table=<country>), Column('id', Integer(), table=<country>, primary_key=True), Column('name', AutoString(), table=<country>, nullable=False), Column('population', Integer(), table=<country>, nullable=False), schema=None),
'__validators__': {},
'__weakref__': None,
'_abc_impl': <_abc._abc_data object at 0x7f236f759800>,
'_sa_class_manager': <ClassManager of <class 'geo_info_svg.models.Country'> at 7f236f760950>,
'geometry': <sqlalchemy.orm.attributes.InstrumentedAttribute object at 0x7f236f78a700>,
'id': <sqlalchemy.orm.attributes.InstrumentedAttribute object at 0x7f236f78a9d0>,
'name': <sqlalchemy.orm.attributes.InstrumentedAttribute object at 0x7f236f78aa70>,
'population': <sqlalchemy.orm.attributes.InstrumentedAttribute object at 0x7f236f78ab10>}) |
Beta Was this translation helpful? Give feedback.
-
|
Do you need the Relationship info or would it work if you indeed just 'cast' to pydantic? I think that's possible by using the sqlmodel instances just to provide the data for vanilla pydantic instances, like the from_orm method / factory does. |
Beta Was this translation helpful? Give feedback.
-
|
@antont Yes, relationship info is important. Otherwise it isn't an entity relationship diagram. 😉 |
Beta Was this translation helpful? Give feedback.
-
|
I just want to say that this would be SO COOL. @DanLipsitt I really hope that you come up with this at some point 😃 |
Beta Was this translation helpful? Give feedback.
-
|
Hi @DanLipsitt , did you make any progress with this? |
Beta Was this translation helpful? Give feedback.
-
|
I would also like to know if you made progress @DanLipsitt :) |
Beta Was this translation helpful? Give feedback.
-
|
this would be amazing! |
Beta Was this translation helpful? Give feedback.
-
|
Are there any news? This would be awesome! What about decomposing the SQLModel into a Dict-ish or into pydantic so erdantic works? |
Beta Was this translation helpful? Give feedback.
-
|
This would be amazing |
Beta Was this translation helpful? Give feedback.
-
|
I was able to create an ERD using sqlmodel through a different tool:
(I have no relationship with the sqleton tool so please do your common sense validation checks) |
Beta Was this translation helpful? Give feedback.
-
|
For those who might end-up here, there's a python module to do the same thing as @zeehio suggested: pip install eralchemy
eralchemy -i sqlite:///my_sqlite.db -o my_er_diagram.pdf |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
First Check
Commit to Help
Example Code
See description
Description
I am trying to add SQLModel support to Erdantic, an entity relationship diagram generator. It supports Pydantic and produces diagrams that look like this:
Wanted Solution
This is hopefully more of a question than a feature request. I would like to know if it is possible to get the metadata that Erdantic needs. You can see instructions and code code showing how this is implemented for Pydantic. It is relatively short. I thought that since SQLModels are Pydantic models I might be able to reuse most of the code, but SQLModel relationship fields appear to be special, and those are crucial.
Wanted Code
The idea is as follows although the way it happens doesn't matter as long as there's a way to do it.
As I understand it,
is_manymeans it is on the many side of a many-to-one or many-to-many relationshipAlternatives
I have tried to figure out if there is a way to cast a SQLModel as a Pydantic model, but python doesn't really support the idea of casting.
Operating System
macOS
Operating System Details
No response
SQLModel Version
0.0.4
Python Version
Python 3.9.5
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions