kj3moraes / premstats

A natural language querying system for Premier League stats
https://premstats-snowy.vercel.app
Apache License 2.0
2 stars 0 forks source link

Pydantic model seperation for Partial updates #26

Open kj3moraes opened 1 month ago

kj3moraes commented 1 month ago

In order to do partial updates, upserts and adds all in the same app, we would need to seperate just like how SQLModel seperates its BaseModels here

# Code above omitted 👆

class HeroBase(SQLModel):
    name: str = Field(index=True)
    secret_name: str
    age: int | None = Field(default=None, index=True)

class Hero(HeroBase, table=True):
    id: int | None = Field(default=None, primary_key=True)

class HeroCreate(HeroBase):
    pass

class HeroPublic(HeroBase):
    id: int

class HeroUpdate(SQLModel):
    name: str | None = None
    secret_name: str | None = None
    age: int | None = None

# Code below omitted 👇
kj3moraes commented 1 month ago

I really don't like this approach because there's so much clutter and boilerplate code. I will have to look at workarounds.