Convenience methods to create multiple models + associated API endpoints #1939
Replies: 4 comments
-
Beta Was this translation helpful? Give feedback.
-
|
👋 I had a similar desire to cut down on boilerplate. I have a wrapper library that has lifecycle hooks, ORM-like DX, easy session management, JSONB mutation tracking, and other rails-like features that greatly simplify working with these models. Check it out! Would love to hear any feedback and have more contributions to it. |
Beta Was this translation helpful? Give feedback.
-
|
@iloveitaly, I can see many similar comments from you promoting your library. You are at risk to be banned if you keep doing this |
Beta Was this translation helpful? Give feedback.
-
|
@YuriiMotov thanks for the heads up! I had a queue of these issues and now that I've fixed all of them in the upstream package I figured I'd post so people know. I've wasted so much time trying to work around these. Will stop if it's annoying though! |
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
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
MultipleModelsdataclass 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 givenMultipleModelsinstance, it can be passed to the proposedregister_endpointsconvenience 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
MutlipleModelsandregister_endpointsapproach 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.
Beta Was this translation helpful? Give feedback.
All reactions