Replies: 2 comments 1 reply
-
I'm more flexible on the Python side than the SQL one, as I have non-python users of the databases, so I move as much correctness checking as I can get away with into the Postgres side. |
Beta Was this translation helpful? Give feedback.
0 replies
-
You can declare primary keys like this, so at least for that purpose you don't need to touch
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
First Check
Commit to Help
Example Code
Description
I have a bunch of standard fields that occur in all (or nearly all!) of my models, and I heavily use Postgres
schema
to help organize by table spaces. Most of my models have a lot of identical or nearly identical boilerplate, which tends to obscure the actual logic. What I'd love to be able to do is lift these things into a base class, or series of base classes, and then my model definitions can concentrate on their actual logic.For instance, I have the concept of a
Dataset
(see above), which is a related set of records that is a) read-only and b) has a lineage to the various versions of the models used to compute the records. So, every table that contains data that is associated with a givenDataset
has the following standardized fields and relationships: adataset_id
, a foreign key fromdataset_id
todatasets.id
, and a primary key overid
,dataset_id
.I'd love to be able to have a common base class, that defines those columns and relationships. What I'm having trouble with is the class variable
__table_args__
, which needs to be extended, as these subclasses have other table level metadata that's not captured in the (mooted) base class' definition. A similar problem arises with defining theschema
, as the best way that I can figure that out is by adding a dict at the end of the__table_args__
, which again is going to not be easy to manage via inheritance. I'm very happy to take any direction here; I'm relatively new to Python but I'm very experienced with databases and SQL.TIA!
Operating System
Linux, macOS
Operating System Details
No response
SQLModel Version
0.0.3
Python Version
3.11.2
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions