ioxiocom / firedantic

Database models for Firestore using Pydantic base models.
BSD 3-Clause "New" or "Revised" License
43 stars 14 forks source link

Support "omit empty" #28

Open lietu opened 3 years ago

lietu commented 3 years ago

Golang firestore library supports the ability to tag fields as omitempty meaning they will not get stored in the DB when not set. This could be done via e.g. combining Optional with a Config option like

class Model(AsyncModel):
  field: Optional[str]
  another: Optional[List[int]]
  # ...

  class Config:
    omitempty = "*"
    # or
    omitempty = ["field", "another"]
lietu commented 3 years ago

Alternatively e.g. by extending Field() or similar from pydantic

antont commented 10 months ago

Pydantic dict() and json(), or the corresponding model_dump() in v2, support the param:

exclude_unset: Whether to exclude fields that are unset or None from the output.

So maybe Firedantic save() could have it similarily easily.

But I agree that model conf for it would be nice.