New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Where to place CRUD operations? #9
Comments
Hey @ignacevau Thank you for your kind words! We put all the CRUD-like logic in For instance, that's how our from datetime import datetime
from typing import Any, Collection, Mapping
from src.database import database, profile
from src.profiles.schemas import ProfileUpdate, ProfileCreate
async def get_profile_by_user_id(user_id: int) -> Mapping[str, Any] | None:
select_query = profile.select().where(profile.c.user_id == user_id)
return await database.fetch_one(select_query)
async def create_profile(profile_data: ProfileCreate) -> Mapping[str, Any]:
select_query = profile.insert().values(**profile_data.dict()).returning(profile)
return await database.fetch_one(select_query) We try to keep our service functions as clean as possible and let them do one thing only. All the validations should be done one abstraction layer above. For example, we must be sure |
@ignacevau I would avoid adding any methods to your database models (Maybe if they only operate on that specific model it should be ok, but they shouldn't change database state) |
First of all - thanks for this beautiful repo!
I noticed that there is no mention of where to store any crud operations in the project structure.
I wonder how you would implement these?
Some implementations I've considered.
However, this way you don't get any autocompletion.
So far, we're using a separate crud folder for each module, but I would love to hear any other recommendations.
The text was updated successfully, but these errors were encountered: