Generate SQLModel table class from dictionary
See original GitHub issueFirst Check
- I added a very descriptive title to this issue.
- I used the GitHub search to find a similar issue and didn’t find it.
- I searched the SQLModel documentation, with the integrated search.
- I already searched in Google “How to X in SQLModel” and didn’t find any information.
- I already read and followed all the tutorial in the docs and didn’t find an answer.
- I already checked if it is not related to SQLModel but to Pydantic.
- I already checked if it is not related to SQLModel but to SQLAlchemy.
Commit to Help
- I commit to help with one of those options 👆
Example Code
`class CRFForm(CRFFormBase, table=True):
patient_id: Optional[uuid.UUID] = Field(default_factory=uuid.uuid4,
primary_key=True, nullable=False,
title="Generate a random UUID4 - PK")
patient_name: str = Field(nullable=False, title='patient_name',
description='patient_name', minlength=10, maxlength=50)
age: int = Field(nullable=False, title='age', description='age', le=120)
is_married: Optional[bool] = Field(default=True, title="is_married")`
Description
Given the following input (for say).
input_dict = { "table_name": "CRFForm", "columns": [ { "name": "patient_id", "title": "", "description": "", "type": uuid.UUID, "default": uuid.uuid4(), "nullable": False, "primary": True }, { "name": "patient_name", "title": "", "description": "", "type": str, "minlength": 10, "maxlength": 50, "nullable": False, "unique": True }, { "name": "age", "title": "", "description": "", "type": int, "nullable": False, "le": 120 }, { "name": "is_married", "title": "", "description": "", "type": bool, "nullable": False } ] }
Wanted Solution
output —> Generate SQLModel class from the above dictionary by satisfying the table relations and constraints
Wanted Code
`class CRFForm(CRFFormBase, table=True):
patient_id: Optional[uuid.UUID] = Field(default_factory=uuid.uuid4,
primary_key=True, nullable=False,
title="Generate a random UUID4 - PK")
patient_name: str = Field(nullable=False, title='patient_name',
description='patient_name', minlength=10, maxlength=50)
age: int = Field(nullable=False, title='age', description='age', le=120)
is_married: Optional[bool] = Field(default=True, title="is_married")`
Alternatives
No response
Operating System
Linux, Windows, macOS
Operating System Details
Windows 10 Laptop and tianglo 3.9 slimbust image
SQLModel Version
0.8
Python Version
3.9
Additional Context
No response
Issue Analytics
- State:
- Created 10 months ago
- Comments:5
All arguments of the
Field
function can be defined:To support foreign key relationships, you should continue with this idea with the
Relationship
function.Added the code here.
https://github.com/Udayaprasad/dynamic_sqlmodel_creator