Better transaction support #62
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request introduces several major improvements to the Mayim library, focusing on enhanced connection pool management, improved transaction coordination, and expanded configuration options. The most significant changes include the introduction of a shared pool registry to prevent duplicate connections, support for connection pool sizing, a more flexible transaction API (including two-phase commit and timeouts), and compatibility updates for newer Python versions.
Connection Pool Management and Sizing:
PoolRegistryto ensure that executors using the same DSN share a single pool instance, preventing duplicate connections and enabling proper transaction coordination (src/mayim/registry.py,src/mayim/mayim.py,tests/conftest.py). [1] [2] [3] [4]min_sizeandmax_sizeparameters inBaseInterfaceand its subclasses, and ensured these are passed through the registry and pool constructors (src/mayim/base/interface.py,src/mayim/lazy/interface.py,src/mayim/sql/postgres/interface.py,src/mayim/mayim.py). [1] [2] [3] [4] [5] [6] [7]Transaction Coordination and API Improvements:
Mayim.transactionAPI to support both old and new usage styles, added options for two-phase commit (use_2pc) and transaction timeouts, and introduced a wrapper for backward compatibility. The new API ensures only registered SQL executors are used and supports both context manager and awaitable usage (src/mayim/mayim.py).SQLExecutorto honor global transaction context, ensuring that rollbacks and transaction context managers interact correctly with coordinated transactions (src/mayim/sql/executor.py). [1] [2]Python Compatibility and Miscellaneous:
setup.cfgand bumped the package version to 1.2.0. [1] [2]src/mayim/exception.py,src/mayim/extension/quart_extension.py,src/mayim/extension/starlette_extension.py,src/mayim/base/executor.py,src/mayim/base/interface.py,src/mayim/lazy/interface.py). [1] [2] [3] [4] [5]These changes collectively modernize the codebase, improve resource management, and provide more robust transactional guarantees for multi-database operations.