v2.0.0
Breaking Changes¶
v2.0.0 is a completely refactored version that is incompatible with v1. Main changes include:
1. Architecture Refactoring¶
- Separated Engine and AsMysql Classes
- New
Engineclass: Independent MySQL connection engine, can be used standalone AsMysqlclass: Business logic development base class, accessesEnginethroughclientattribute- This design completely separates connection management and business logic
2. Result Class Changes¶
- Error Attribute Renaming
Result.err→Result.error- More compliant with Python naming conventions
3. API Changes¶
- Connection Method Changes
- v1: Auto-connect after inheriting
AsMysql -
v2: Need to explicitly create
Engineand callconnect() -
Execution Method Changes
- v1: AsMysql
self.client.execute(...) - v2: AsMysql
self.client.execute(...)(unchanged, butclientis now anEngineinstance)
New Features¶
1. Engine Class¶
A brand new connection engine class providing the following features:
-
URL Connection String Support
-
Connection Status Monitoring
-
Flexible Connection Management
- Support for
async withcontext manager - Support for
await engine()syntax -
Support for
await enginesyntax -
Connection Pool Configuration
min_pool_size: Minimum connectionsmax_pool_size: Maximum connectionspool_recycle: Idle connection recycle timeconnect_timeout: Connection timeout
2. Result Class Enhancements¶
- Error Information Access
error_no: Get MySQL error codeerror_msg: Get MySQL error message-
error: Get complete error exception object -
Streaming Query Support
-
Context Manager Support
-
Async Iterator Support
-
Custom Result Types
3. Execution Method Enhancements¶
- execute() Method
- Support for
streamparameter: Enable streaming query - Support for
result_classparameter: Specify return result type - Support for
commitparameter: Control transaction commit -
Support for multiple calling methods:
result = await engine.execute(...)async with engine.execute(...) as result:async for item in engine.execute(...):
-
execute_many() Method
- Batch execute SQL statements
- Support for same parameter options
4. Type Hints¶
- Complete type hint support
- Support for generic types (
Result[T]) - IDE-friendly code completion
5. Testing¶
- New pytest test suite
- Covers main functional scenarios
- Support for Mock testing
Updates¶
1. Package Management Tool¶
- Use
uvas package management tool - Faster dependency installation speed
- Better dependency resolution
2. Code Quality¶
- Improved code structure
- Better error handling
- Clearer docstrings
Core Features¶
v2 version retains the core features of v1:
- Easy to Use
- asmysql is an easy-to-use library that wraps aiomysql
-
Provides more friendly API
-
Connection Pool Management
- Automatic MySQL connection pool management
- Support for reconnection mechanism
-
Connection pool status monitoring
-
Error Handling
- Global automatic capture of
MysqlErrorerrors - Provides error code and error message access
-
Elegant error handling mechanism
-
Separation of Execution and Retrieval
- Separation of SQL statement execution and result retrieval
- Support for multiple data retrieval methods
-
Flexible result processing
-
Type Hints
- Complete Python type hints
- IDE-friendly code completion
-
Type safety
-
Business Logic Development
- Directly inherit
AsMysqlclass for logic development - Clear code organization
- Easy to test and maintain