Let's say I have two SQL tables address
and email
tables.
For the address
table I may have the following generic fields:
postal_code
street_name
and additionally, I would want the following two fields:
is_verified
, of typeEnum
with only one of the three variants inUnverified
,Verified
,InProgress
in_progress_description
, aString
of a comment on the progress status
Similarly, for the email
table, I would want the following generic field:
email_addr
of typepydantic.EmailStr
and also the fields is_verified
and in_progress_description
.
Should I create a mixin like the following for the verifiability of the two tables (SQLModels) or how should I write my Email
and Address
classes to avoid duplicating codes for is_verified
and in_progress_description
fields?
=== Mixin ===
class VerifiableMixin:
verification_status: VerificationStatusEnum = VerificationStatusEnum.Unverified
verification_description: str = None
Then have the Email(SQLModel, table=True)
subclassing it too.
class Email(SQLModel, VerifiableMixin, table=True):
email_addr: EmailStr
=== SQLModel ===
class VerifiableBaseSQLModel:
verification_status: VerificationStatusEnum = Field(default=VerificationStatusEnum.Unverified)
verification_description: str = Field(default=None)
class Email(SQLModel, VerifiableBaseSQLModel, table=True):
email_addr: EmailStr