__init__.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. """
  2. MySQL数据库工具库
  3. 提供MySQL数据库的连接池管理、基础CRUD操作、高级查询功能和事务管理。
  4. 主要功能:
  5. - 连接池管理
  6. - 基础CRUD操作(增删改查)
  7. - 分页、排序、聚合查询
  8. - 事务管理
  9. - 异常处理和日志记录
  10. 使用示例:
  11. from utils.mysql import mysql_db
  12. # 基础查询
  13. users = mysql_db.select('users', where='age > %s', where_params=(18,))
  14. # 分页查询
  15. result = mysql_db.paginate('users', page=1, page_size=10)
  16. # 事务操作
  17. with mysql_db.transaction():
  18. mysql_db.insert('users', {'name': 'John', 'age': 25})
  19. mysql_db.update('users', {'age': 26}, 'name = %s', ('John',))
  20. """
  21. # 直接导入所有模块(pymysql已安装,无需延迟导入)
  22. from .mysql_transaction import mysql_transaction as mysql_db
  23. from .mysql_pool import mysql_pool
  24. from .mysql_helper import mysql_helper
  25. from .mysql_advanced import mysql_advanced
  26. from .mysql_exceptions import (
  27. MySQLBaseException,
  28. MySQLConnectionError,
  29. MySQLConfigError,
  30. MySQLQueryError,
  31. MySQLTransactionError,
  32. MySQLPoolError,
  33. MySQLValidationError
  34. )
  35. # 版本信息
  36. __version__ = '1.0.0'
  37. __author__ = 'MySQL Utils'
  38. # 导出主要接口
  39. __all__ = [
  40. # 主要操作接口
  41. 'mysql_db', # 主要使用的接口,包含所有功能
  42. # 各功能模块
  43. 'mysql_pool', # 连接池管理
  44. 'mysql_helper', # 基础CRUD操作
  45. 'mysql_advanced', # 高级查询功能
  46. # 异常类
  47. 'MySQLBaseException',
  48. 'MySQLConnectionError',
  49. 'MySQLConfigError',
  50. 'MySQLQueryError',
  51. 'MySQLTransactionError',
  52. 'MySQLPoolError',
  53. 'MySQLValidationError',
  54. # 版本信息
  55. '__version__'
  56. ]