asmysql v2 Changelog¶
This document records all changes in asmysql v2 version.
v2.1.0¶
New Features¶
- Connection Init SQL (
init_sql): Addedinit_sqlparameter to automatically execute preset SQL on each new TCP connection's first use. Ideal for ClickHouse async insert configuration, MySQL session variable setup, and similar scenarios. UsesWeakKeyDictionaryto track initialized connections. Fully backward compatible.
Breaking Changes¶
- Auto-Commit Mechanism Refactored: Removed
auto_commitEngine parameter andcommitexecute/Result parameter, replaced with SQL first-keyword-based auto-commit mechanism (_should_commit()). Write operations auto-COMMIT, read operations do not commit, stream mode does not commit - Removed Engine
streamParameter:streamis no longer an Engine class attribute, only available atexecute()method level - Removed Engine
result_classParameter:result_classis no longer an Engine class attribute or constructor parameter, only available at theexecute()/execute_many()method level, defaulting totuple
Bug Fixes¶
- Fixed 6 connection leak issues:
fetch_all()custom type leak, double release after error,async for+breakleak, non-MySQLError exception leak,__del__crash, DDL/DML statements not releasing connections - Fixed 5 logic errors:
echo_sql_logURL parsing,oroperator overriding falsy values, concurrent race conditions, pool null passing, generic parameter semantic error - Fixed 5 medium/low-severity issues:
release_connections()null check,@lru_cachememory leak,error_msgformatting,iterate()check inconsistency, property access crashes
Documentation¶
- Fixed non-existent API usage in homepage examples
- Added
init_sqldocumentation acrossconnection.md,api.md, andexamples.md(both Chinese and English versions) - Rewrote transaction control documentation to describe SQL statement type-based auto-commit mechanism
- Fixed API documentation signatures: removed non-existent
close/commitparameters
Testing¶
- Added
test_engine_init_sql.pycoveringinit_sqlcore functionality and edge cases - Rewrote integration test
enginefixture to auto-select test database viainit_sql=USE <test_db> - Removed Engine
result_classrelated test cases fromtest_mock_engine.py
v2.0.0¶
Breaking Changes¶
v2.0.0 is a completely refactored version that is incompatible with v1. Main changes include:
- Architecture Refactoring: Separated
EngineandAsMysqlclasses, added independentEngineclass to handle MySQL connections and execute statements - Result Class Changes:
Result.errattribute renamed toResult.error - API Changes: Connection method changed from auto-connect to explicitly creating
Engineand callingconnect()
New Features¶
- Engine Class: Brand new connection engine class with URL connection string support, connection status monitoring, and flexible connection management
- Result Class Enhancements: Support for error information access (
error_no,error_msg), streaming queries, context managers, async iterators, and custom result types - Execution Method Enhancements:
execute()method supportsstream,result_classparameters and multiple calling methods - Type Hints: Complete type hint support with generic types (
Result[T]) - Testing: New pytest test suite covering main functional scenarios
Updates¶
- Package Management Tool: Using
uvas package management tool - Code Quality: Improved code structure, error handling, and docstrings
Core Features¶
v2 version retains the core features of v1:
- Easy to Use: asmysql is an easy-to-use library that wraps aiomysql
- Connection Pool Management: Automatic MySQL connection pool management with reconnection mechanism
- Error Handling: Global automatic capture of
MysqlErrorerrors - Separation of Execution and Retrieval: Separation of SQL statement execution and result retrieval
- Type Hints: Complete Python type hint support
- Business Logic Development: Directly inherit
AsMysqlclass for logic development
Migration Guide¶
For detailed migration guide, please refer to Migration Guide.