lush-sqlalchemyx 0.1.0__tar.gz → 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. {lush_sqlalchemyx-0.1.0 → lush_sqlalchemyx-0.2.0}/PKG-INFO +12 -3
  2. {lush_sqlalchemyx-0.1.0 → lush_sqlalchemyx-0.2.0}/pyproject.toml +31 -6
  3. lush_sqlalchemyx-0.2.0/src/lush_sqlalchemyx/_compat.py +24 -0
  4. lush_sqlalchemyx-0.2.0/src/lush_sqlalchemyx/base/dal/__init__.py +147 -0
  5. lush_sqlalchemyx-0.2.0/src/lush_sqlalchemyx/base/dal/_async.py +869 -0
  6. lush_sqlalchemyx-0.2.0/src/lush_sqlalchemyx/base/dal/_common.py +340 -0
  7. lush_sqlalchemyx-0.2.0/src/lush_sqlalchemyx/base/dal/_sync.py +858 -0
  8. lush_sqlalchemyx-0.2.0/src/lush_sqlalchemyx/integrations/flask/__init__.py +8 -0
  9. lush_sqlalchemyx-0.2.0/src/lush_sqlalchemyx/integrations/flask/ext.py +240 -0
  10. {lush_sqlalchemyx-0.1.0 → lush_sqlalchemyx-0.2.0}/src/lush_sqlalchemyx/mgrs/__init__.py +15 -1
  11. {lush_sqlalchemyx-0.1.0 → lush_sqlalchemyx-0.2.0}/src/lush_sqlalchemyx/mgrs/mysql/__init__.py +15 -0
  12. lush_sqlalchemyx-0.2.0/src/lush_sqlalchemyx/mgrs/mysql/sync_manager.py +172 -0
  13. lush_sqlalchemyx-0.2.0/src/lush_sqlalchemyx/mgrs/mysql/sync_mapper.py +61 -0
  14. {lush_sqlalchemyx-0.1.0 → lush_sqlalchemyx-0.2.0}/src/lush_sqlalchemyx/shortcuts/meta.py +1 -1
  15. lush_sqlalchemyx-0.1.0/src/lush_sqlalchemyx/base/dal/__init__.py +0 -2013
  16. {lush_sqlalchemyx-0.1.0 → lush_sqlalchemyx-0.2.0}/README.md +0 -0
  17. {lush_sqlalchemyx-0.1.0 → lush_sqlalchemyx-0.2.0}/src/lush_sqlalchemyx/__init__.py +0 -0
  18. {lush_sqlalchemyx-0.1.0 → lush_sqlalchemyx-0.2.0}/src/lush_sqlalchemyx/base/__init__.py +0 -0
  19. {lush_sqlalchemyx-0.1.0 → lush_sqlalchemyx-0.2.0}/src/lush_sqlalchemyx/integrations/__init__.py +0 -0
  20. {lush_sqlalchemyx-0.1.0 → lush_sqlalchemyx-0.2.0}/src/lush_sqlalchemyx/integrations/fastapi/__init__.py +0 -0
  21. {lush_sqlalchemyx-0.1.0 → lush_sqlalchemyx-0.2.0}/src/lush_sqlalchemyx/integrations/fastapi/depends/__init__.py +0 -0
  22. {lush_sqlalchemyx-0.1.0 → lush_sqlalchemyx-0.2.0}/src/lush_sqlalchemyx/mgrs/mysql/manager.py +0 -0
  23. {lush_sqlalchemyx-0.1.0 → lush_sqlalchemyx-0.2.0}/src/lush_sqlalchemyx/mgrs/mysql/mapper.py +0 -0
  24. {lush_sqlalchemyx-0.1.0 → lush_sqlalchemyx-0.2.0}/src/lush_sqlalchemyx/py.typed +0 -0
  25. {lush_sqlalchemyx-0.1.0 → lush_sqlalchemyx-0.2.0}/src/lush_sqlalchemyx/same_impl_just_warn_wrapper.py +0 -0
  26. {lush_sqlalchemyx-0.1.0 → lush_sqlalchemyx-0.2.0}/src/lush_sqlalchemyx/shortcuts/__init__.py +0 -0
@@ -1,14 +1,23 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: lush-sqlalchemyx
3
- Version: 0.1.0
4
- Summary: see README.md
3
+ Version: 0.2.0
4
+ Summary: SQLAlchemy helpers (DAL) and async MySQL managers, with some web frameworks integrations
5
5
  Author: straydragon
6
- Requires-Dist: sqlalchemy[asyncio]>=2.0.43
6
+ Author-email: straydragon <straydragonl@foxmail.com>
7
+ License: Apache-2.0
8
+ Classifier: Programming Language :: Python :: 3 :: Only
9
+ Classifier: Programming Language :: Python :: 3.10
10
+ Requires-Dist: sqlalchemy>=2.0.21
7
11
  Requires-Dist: pydantic>=2.11.0,<3.0.0
8
12
  Requires-Dist: typing-extensions>=4.12.2
9
13
  Requires-Dist: lush-pydanticx>=0.1.0
10
14
  Requires-Dist: lush-stdx>=0.1.0
15
+ Requires-Dist: lush-dal-protocol>=0.1.0
16
+ Requires-Dist: sqlalchemy[asyncio]>=2.0.43 ; extra == 'asyncio'
17
+ Requires-Dist: flask-sqlalchemy>=3.1.1 ; extra == 'flask'
11
18
  Requires-Python: >=3.10
19
+ Provides-Extra: asyncio
20
+ Provides-Extra: flask
12
21
  Description-Content-Type: text/markdown
13
22
 
14
23
  # lush-sqlalchemyx
@@ -1,20 +1,30 @@
1
1
  [project]
2
2
  name = "lush-sqlalchemyx"
3
- version = "0.1.0"
4
- description = "see README.md"
3
+ version = "0.2.0"
4
+ description = "SQLAlchemy helpers (DAL) and async MySQL managers, with some web frameworks integrations"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.10"
7
- authors = [{ name = "straydragon" }]
7
+ authors = [{ name = "straydragon", email = "straydragonl@foxmail.com" }]
8
+ license = { text = "Apache-2.0" }
9
+ classifiers = [
10
+ "Programming Language :: Python :: 3 :: Only",
11
+ "Programming Language :: Python :: 3.10",
12
+ ]
8
13
  dependencies = [
9
- "sqlalchemy[asyncio]>=2.0.43",
14
+ "sqlalchemy>=2.0.21",
10
15
  "pydantic>=2.11.0,<3.0.0",
11
16
  "typing-extensions>=4.12.2",
12
17
  "lush-pydanticx>=0.1.0",
13
18
  "lush-stdx>=0.1.0",
19
+ "lush-dal-protocol>=0.1.0",
14
20
  ]
15
21
 
22
+ [project.optional-dependencies]
23
+ asyncio = ["sqlalchemy[asyncio]>=2.0.43"]
24
+ flask = ["flask-sqlalchemy>=3.1.1"]
25
+
16
26
  [build-system]
17
- requires = ["uv_build>=0.10.12,<0.11.0"]
27
+ requires = ["uv_build>=0.10.12,<0.12.0"]
18
28
  build-backend = "uv_build"
19
29
 
20
30
  [tool.uv]
@@ -23,6 +33,7 @@ package = true
23
33
  [tool.uv.sources]
24
34
  lush-pydanticx = { path = "../lush-pydanticx" }
25
35
  lush-stdx = { path = "../lush-stdx" }
36
+ lush-dal-protocol = { path = "../lush-dal-protocol" }
26
37
 
27
38
  [dependency-groups]
28
39
  dev = [
@@ -31,16 +42,30 @@ dev = [
31
42
  "pytest-asyncio>=1.1.0",
32
43
  "pytest-cov>=6.2.1",
33
44
  "aiosqlite>=0.20.0",
45
+ "aiomysql>=0.2.0",
34
46
  "fastapi[standard]>=0.117.1",
47
+ "sqlalchemy[asyncio]>=2.0.43",
48
+ "flask-sqlalchemy>=3.1.1",
49
+ "flask>=3.0.0",
35
50
  ]
36
51
 
37
52
  [tool.pytest.ini_options]
38
- addopts = "--import-mode=importlib --cov=lush_sqlalchemyx --cov-report=term-missing"
53
+ addopts = "--import-mode=importlib --cov=lush_sqlalchemyx --cov-branch --cov-report=term-missing --cov-fail-under=100"
39
54
  testpaths = ["tests"]
40
55
  asyncio_mode = "auto"
41
56
  asyncio_default_fixture_loop_scope = "function"
42
57
  asyncio_default_test_loop_scope = "function"
43
58
 
59
+ [tool.coverage.run]
60
+ branch = true
61
+
62
+ [tool.coverage.report]
63
+ exclude_also = [
64
+ "if TYPE_CHECKING:",
65
+ "if __name__ == .__main__.:",
66
+ "@(abc\\.)?abstractmethod",
67
+ ]
68
+
44
69
  [tool.ruff]
45
70
  line-length = 140
46
71
  indent-width = 4
@@ -0,0 +1,24 @@
1
+ """运行时可选依赖检测."""
2
+
3
+ from __future__ import annotations
4
+
5
+ _HAS_ASYNC: bool
6
+ try:
7
+ from sqlalchemy.ext.asyncio import AsyncSession as _AsyncSession # noqa: F401
8
+
9
+ _HAS_ASYNC = True
10
+ except ImportError: # pragma: no cover
11
+ _HAS_ASYNC = False
12
+
13
+
14
+ def require_async() -> None:
15
+ """当异步支持不可用时立即抛出 ``ImportError``.
16
+
17
+ 应在依赖 ``sqlalchemy.ext.asyncio`` 的文件 **模块级别** 调用,
18
+ 以便用户看到清晰的错误信息而非深层调用栈中的 ``AttributeError``.
19
+ """
20
+ if not _HAS_ASYNC:
21
+ raise ImportError(
22
+ "Async support requires 'sqlalchemy[asyncio]' (greenlet). "
23
+ "Install with: pip install 'lush-sqlalchemyx[asyncio]'"
24
+ )
@@ -0,0 +1,147 @@
1
+ """``lush_sqlalchemyx.base.dal`` 公共导出层.
2
+
3
+ 所有原先可从此模块导入的符号保持不变, 同时新增同步模式相关符号.
4
+ """
5
+
6
+ # --- shared (sync/async agnostic) ---
7
+ from ._common import (
8
+ DEFAULT_RETRY_CONFIG,
9
+ OPTIMISTIC_LOCK_ERROR_MSG_TRAIT,
10
+ PESSIMISTIC_LOCK_ERROR_MSG_TRAIT,
11
+ READONLY_SESSION_FLAG,
12
+ BaseCU,
13
+ BaseDTO,
14
+ BaseModelT,
15
+ CUModelT,
16
+ DBRetryableError,
17
+ DTOModelT,
18
+ FieldMixin,
19
+ ReadOnlyMixin,
20
+ RetryConfig,
21
+ SQLATableT,
22
+ SoftDeleteTableMixin,
23
+ StdBaseCU,
24
+ StdBaseDTO,
25
+ T,
26
+ V,
27
+ _ensure_strict_fields,
28
+ escape_like,
29
+ filtered_in_sql_values,
30
+ )
31
+
32
+ # Event listener references — accessed by tests via getattr(module, name).
33
+ from ._common import __prevent_readonly_write as __prevent_readonly_write # noqa: F401, PLC2701
34
+ from ._common import __receive_before_flush as __receive_before_flush # noqa: F401, PLC2701
35
+
36
+ # --- async (requires sqlalchemy[asyncio]) ---
37
+ from ._async import (
38
+ AsyncBaseDAL,
39
+ AsyncRawDAL,
40
+ AsyncRawReadDAL,
41
+ AsyncReadDAL,
42
+ AsyncSQLATableT,
43
+ AsyncSqlATableBase,
44
+ AsyncWriteDAL,
45
+ AsyncXDALOp,
46
+ BasicAsyncBaseTable,
47
+ ReadOnlyAsyncBaseDAL,
48
+ ReadOnlyBasicAsyncBaseTable,
49
+ StdAsyncBaseTable,
50
+ StdReadOnlyBasicAsyncBaseTable,
51
+ async_temp_set_lock_wait_timeout,
52
+ async_with_retry,
53
+ )
54
+
55
+ # --- lush-dal-protocol protocols (ORM 无关的抽象层) ---
56
+ from lush_dal_protocol import (
57
+ AsyncBaseDALProtocol,
58
+ AsyncReadDALProtocol,
59
+ AsyncWriteDALProtocol,
60
+ SyncBaseDALProtocol,
61
+ SyncReadDALProtocol,
62
+ SyncWriteDALProtocol,
63
+ )
64
+
65
+ # --- sync ---
66
+ from ._sync import (
67
+ BasicSyncBaseTable,
68
+ ReadOnlySyncBaseDAL,
69
+ ReadOnlySyncBaseTable,
70
+ StdReadOnlySyncBaseTable,
71
+ StdSyncBaseTable,
72
+ SyncBaseDAL,
73
+ SyncRawDAL,
74
+ SyncRawReadDAL,
75
+ SyncReadDAL,
76
+ SyncSQLATableT,
77
+ SyncSqlATableBase,
78
+ SyncWriteDAL,
79
+ SyncXDALOp,
80
+ sync_temp_set_lock_wait_timeout,
81
+ sync_with_retry,
82
+ )
83
+
84
+ __all__ = (
85
+ # common
86
+ "DEFAULT_RETRY_CONFIG",
87
+ "OPTIMISTIC_LOCK_ERROR_MSG_TRAIT",
88
+ "PESSIMISTIC_LOCK_ERROR_MSG_TRAIT",
89
+ "READONLY_SESSION_FLAG",
90
+ "BaseCU",
91
+ "BaseDTO",
92
+ "BaseModelT",
93
+ "CUModelT",
94
+ "DBRetryableError",
95
+ "DTOModelT",
96
+ "FieldMixin",
97
+ "ReadOnlyMixin",
98
+ "RetryConfig",
99
+ "SQLATableT",
100
+ "SoftDeleteTableMixin",
101
+ "StdBaseCU",
102
+ "StdBaseDTO",
103
+ "T",
104
+ "V",
105
+ "_ensure_strict_fields",
106
+ "escape_like",
107
+ "filtered_in_sql_values",
108
+ # async
109
+ "AsyncBaseDAL",
110
+ "AsyncRawDAL",
111
+ "AsyncRawReadDAL",
112
+ "AsyncReadDAL",
113
+ "AsyncSQLATableT",
114
+ "AsyncSqlATableBase",
115
+ "AsyncWriteDAL",
116
+ "AsyncXDALOp",
117
+ "BasicAsyncBaseTable",
118
+ "ReadOnlyAsyncBaseDAL",
119
+ "ReadOnlyBasicAsyncBaseTable",
120
+ "StdAsyncBaseTable",
121
+ "StdReadOnlyBasicAsyncBaseTable",
122
+ "async_temp_set_lock_wait_timeout",
123
+ "async_with_retry",
124
+ # sync
125
+ "BasicSyncBaseTable",
126
+ "ReadOnlySyncBaseDAL",
127
+ "ReadOnlySyncBaseTable",
128
+ "StdReadOnlySyncBaseTable",
129
+ "StdSyncBaseTable",
130
+ "SyncBaseDAL",
131
+ "SyncRawDAL",
132
+ "SyncRawReadDAL",
133
+ "SyncReadDAL",
134
+ "SyncSQLATableT",
135
+ "SyncSqlATableBase",
136
+ "SyncWriteDAL",
137
+ "SyncXDALOp",
138
+ "sync_temp_set_lock_wait_timeout",
139
+ "sync_with_retry",
140
+ # lush-dal-protocol protocols
141
+ "AsyncBaseDALProtocol",
142
+ "AsyncReadDALProtocol",
143
+ "AsyncWriteDALProtocol",
144
+ "SyncBaseDALProtocol",
145
+ "SyncReadDALProtocol",
146
+ "SyncWriteDALProtocol",
147
+ )