GithubHelp home page GithubHelp logo

sqlalchemy sessions about python-ddd HOT 1 CLOSED

SarloAkrobata avatar SarloAkrobata commented on July 17, 2024
sqlalchemy sessions

from python-ddd.

Comments (1)

pgorecki avatar pgorecki commented on July 17, 2024 2

I'll try to walk you through:

get_bidding_details is a GetBiddingDetails query handler as it is decorated with @bidding_module.query_handler.

When calling application.execute_query(GetBiddingDetails(...)), get_bidding_details is being called within a TransactionContext. The role of a TransactionContext is to inject any parameters required by a function (via its dependency provider).

This is the query execution flow flow:

  1. TransactionContext is entered (https://github.com/pgorecki/python-ddd/blob/79f9558a8d6a7e97e7f7b3fdb084517fd43ee6b1/src/config/container.py#L103C9-L103C37), a new session is created
  2. The handler's params are provided by TransactionContext, and the handler is executed
  3. TransactionContext is exited (
    def on_exit_transaction_context(ctx, exc_type, exc_val, exc_tb):
    ), the session is committed and closed.

Note that:

  1. TransactionContext uses IocProvider to provide any dependencies the handler requires.
  2. some of the dependencies are transaction scoped (i.e. session, repositories, logger), and some of them are singletons (i.e. sqlalchemy engine) - that's why we have TransactionContainer and TopLevelContainer.

Now let's back to your original question about the number of database connections. This is controlled by the pool_size parameter of create_engine, which defaults to 5. (https://docs.sqlalchemy.org/en/20/core/engines.html#sqlalchemy.create_engine.params.pool_size)

More about pooling: https://docs.sqlalchemy.org/en/20/core/pooling.html

Hope this helps.

from python-ddd.

Related Issues (6)

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.