You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
# A reproducible repository which includes the proposed convenience objects # (and passes all the tests from the official tutorial):https://github.com/cisaacstern/sqlmodel-abstraction# All of the proposed code lives in:https://github.com/cisaacstern/sqlmodel-abstraction/blob/main/project/abstractions.py
To achieve this, I've drafted a MultipleModels dataclass which takes base and response models as input, and generates the remaining (table, creation, and update) models programmatically; e.g., here. To register API endpoints for a given MultipleModels instance, it can be passed to the proposed register_endpoints convenience function; e.g., here.
The example repo for this feature proposal is a fully reproducible example project which passes all the same tests as the tutorial project in the SQLModel docs.
Wanted Solution
SQLModel currently provides other convenience methods (e.g., create_engine).
Whether it is via some version of the MutlipleModels and register_endpoints approach I've proposed, or some other methods, I would like to be have convenience methods that abstract away boilerplate code from the process of implementing the multiple models with inheritance design pattern.
Wanted Code
# This is an abbreviated `main.py` for a SQLModel project that uses the proposed features# Full file: https://github.com/cisaacstern/sqlmodel-abstraction/blob/main/project/main.py# Some imports omitted herefromsqlmodelimportMultipleModels, register_endpointsclassHeroBase(SQLModel):
name: strsecret_name: strage: Optional[int] =NoneclassHeroRead(HeroBase):
id: inthero_models=MultipleModels(path="/heroes/", base=HeroBase, response=HeroRead)
# `engine` assignment and `get_session` definition omitted hereapp=FastAPI()
register_endpoints(app, models=hero_models, get_session=get_session)
Alternatives
If this is out of scope for SQLModel, I would nonetheless greatly appreciate feedback on any pitfalls that may arise if I implement the proposed abstractions in production.
If this is within scope for SQLModel, I would happily adapt my example repo into a PR, if it seems like a good enough start.
cisaacstern
changed the title
Convenience abstractions to create multiple model families + associated CRUD API endpoints
Convenience methods to create multiple model families + associated CRUD API endpoints
Nov 24, 2021
cisaacstern
changed the title
Convenience methods to create multiple model families + associated CRUD API endpoints
Convenience methods to create multiple models + associated CRUD API endpoints
Nov 24, 2021
cisaacstern
changed the title
Convenience methods to create multiple models + associated CRUD API endpoints
Convenience methods to create multiple models + associated API endpoints
Nov 24, 2021
First Check
Commit to Help
Example Code
Description
The multiple models with inheritance design pattern is awesome. I would like to be able to implement it more concisely.
To achieve this, I've drafted a
MultipleModels
dataclass which takes base and response models as input, and generates the remaining (table, creation, and update) models programmatically; e.g., here. To register API endpoints for a givenMultipleModels
instance, it can be passed to the proposedregister_endpoints
convenience function; e.g., here.The example repo for this feature proposal is a fully reproducible example project which passes all the same tests as the tutorial project in the SQLModel docs.
Wanted Solution
SQLModel currently provides other convenience methods (e.g.,
create_engine
).Whether it is via some version of the
MutlipleModels
andregister_endpoints
approach I've proposed, or some other methods, I would like to be have convenience methods that abstract away boilerplate code from the process of implementing the multiple models with inheritance design pattern.Wanted Code
Alternatives
If this is out of scope for SQLModel, I would nonetheless greatly appreciate feedback on any pitfalls that may arise if I implement the proposed abstractions in production.
If this is within scope for SQLModel, I would happily adapt my example repo into a PR, if it seems like a good enough start.
Thanks in advance for your consideration.
Operating System
Linux, macOS
Operating System Details
No response
SQLModel Version
0.0.4
Python Version
Additional Context
As noted in the example repo README, these ideas arose while exploring SQLModel for a database + API for Pangeo Forge.
The text was updated successfully, but these errors were encountered: