AliRn76 / panther

Fast & Friendly Web Framework For Building Async APIs With Python 3.10+
https://pantherpy.github.io
BSD 3-Clause "New" or "Revised" License
285 stars 17 forks source link

added SerializableModel for being able to serialize any model #95

Open aminiun opened 4 months ago

aminiun commented 4 months ago

Sample 1:

# Model
class User(SerializableModel, Base):
    __tablename__ = "user_account"

    id: Mapped[int] = mapped_column(primary_key=True)
    name: Mapped[str] = mapped_column(String(30))

API Response:

[{"id":1,"name":"a"},{"id":2,"name":"b"}]

Sample 2:

# Model
class User(SerializableModel, Base):
    __tablename__ = "user_account"

    serializable_fields = (
        "name",
    )

    id: Mapped[int] = mapped_column(primary_key=True)
    name: Mapped[str] = mapped_column(String(30))

API Response:

[{"name":"a"},{"name":"b"}]