Enough to have create_db_and_tables() in the startup event, no need to have it in main(), in fact given uvicorn is the driver of this app, we can remove both main and the if __name__ == "__main__": block. Nice that you created + re-used the create_db_and_tables() function = modular.
You can also remove async def root():
The DB logic is embedded in the FastAPI views, this is ok, but I think we said to use functions in database.py to make it more modular.
"# for production echo is False" - you could use an environment variable to define this, see: https://pybit.es/articles/how-to-handle-environment-variables-in-python/ (when you move from sqlite to Postgres you also want to load the DB string from the environment rather than hardcoding it)
I would use singular for my model name, so Animal and Image (like docs using Hero and Team)
Same comment regarding grouping imports as per PEP8 above
Not sure if optional is right here? number_observed: Optional[int] = 1, shouldn't that be number_observed: int = 1?
I recommend running flake8 / black against your code, there are extra spaces, here for example: class Images (SQLModel, table = True): (should be: class Images(SQLModel, table=True):)
image_type: str: if there is a limited set of options you could define those in an enum(eration) type
@JimLakis well done!
Please submit code in a PR so we do the formal GitHub review process (like dev teams do) - thanks.
https://github.com/JimLakis/PDM_Wildlife/blob/main/app.py
create_db_and_tables()
in the startup event, no need to have it in main(), in fact given uvicorn is the driver of this app, we can remove both main and theif __name__ == "__main__":
block. Nice that you created + re-used thecreate_db_and_tables()
function = modular.async def root():
https://github.com/JimLakis/PDM_Wildlife/blob/main/database.py
https://github.com/JimLakis/PDM_Wildlife/blob/main/models.py
Animal
andImage
(like docs usingHero
andTeam
)number_observed: Optional[int] = 1
, shouldn't that benumber_observed: int = 1
?class Images (SQLModel, table = True):
(should be:class Images(SQLModel, table=True):
)image_type: str
: if there is a limited set of options you could define those in an enum(eration) typeCan you review please?
Hope these suggestions help you, let me know if you have any questions ...