Giter VIP home page Giter VIP logo

Comments (7)

mattupstate avatar mattupstate commented on July 20, 2024

@FindBoat Explained here

from overholt.

FindBoat avatar FindBoat commented on July 20, 2024

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.
If I'm using obj.model.query, it seems to break the abstract of Service.

from overholt.

mattupstate avatar mattupstate commented on July 20, 2024

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()

from overholt.

FindBoat avatar FindBoat commented on July 20, 2024

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.

from overholt.

mattupstate avatar mattupstate commented on July 20, 2024

Thats an assumption you have made for yourself. I've never suggested that custom service methods must use the methods provided by Service. It is by no means a complete abstraction on top of SQLAlchemy either. As described in the blog post, the service layer is to expose a logical API that encapsulates your platforms core logic. That service can then be used in multiple contexts such as a web app, or even a CLI if you wanted to build one on top of it.

from overholt.

FindBoat avatar FindBoat commented on July 20, 2024

I see. That make sense. Thank you very much Matt! Also thank you for sharing your insight on Flask.

from overholt.

mattupstate avatar mattupstate commented on July 20, 2024

No sweat! Appreciate the discussion.

from overholt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.