A question for core.Service #26
Comments
Thanks for the explanation. I think my second question is not answered. Actually I can't use some sqlalchemy's query method by calling Service methods. For instance, I want to query obj whose attr1=val1 and attr2=val2 or more complicated. |
Nothing is stopping you from using the models directly, or creating a service method that abstracts the query you're trying to make. A hypothetical example: class UserService(Service):
def custom_method(self, email):
return self.__model__.query.filter(self.__model__.email==email).all() |
Well, I assume that Service abstracts external stuffs like sqlalchemy, and UserService should only call methods provided by Service. Thus in the future, suppose we want to migrate from sqlalchemy to something else, we only need to change the implementation of Service. However, if we are calling sqlalchemy methods directly in UserService, it breaks the assumption above. Otherwise, what's the benefit to define a Service rather than using external stuffs directly. |
Thats an assumption you have made for yourself. I've never suggested that custom service methods must use the methods provided by |
I see. That make sense. Thank you very much Matt! Also thank you for sharing your insight on Flask. |
No sweat! Appreciate the discussion. |
I got a quick question for core.Service. So what's the point to wrap sqlalchemy's methods into Service rather than call them directly in each application?
Also I didn't find a way to use some sqlalchemy's methods like (query.filter, concatenating multiple filter_by etc.) without calling directly model.query blabla. It seems that Service doesn't provide all methods of sqlalchemy.
The text was updated successfully, but these errors were encountered: