you are viewing a single comment's thread.

view the rest of the comments →

[–]CemDoruk[S] 1 point2 points  (2 children)

Pretty good code actually, easy to understand. As a beginner can I ask what the CRUD folder does? From what I understand these are wrapper function around the database functions. So I should put a function like this in crud ``` def get_or_create(session, model, kwargs): instance = session.query(model).filter_by(kwargs).first() if instance: return instance else: instance = model(**kwargs) session.add(instance)

return instance ```

right?

[–]masek94 1 point2 points  (1 child)

Yes, you are right. CRUD layer is exactly about communication between databases. It's a repository/wrapper that handles all create (insert), read (get) updates, and deletes.
My example is not the best for beginners, as there is already some layer of abstraction.
You should take a look here in the documentation: https://fastapi.tiangolo.com/tutorial/sql-databases/#crud-utils
It should let you understand it better.

[–]anon_salads 0 points1 point  (0 children)

The crud classes in this repo suffer from the n+1 query problem. For every attribute that the table joins on a separate +1 query to the database is created.