ezKit 3.0.0__tar.gz → 3.0.1__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.
- {ezkit-3.0.0/ezKit.egg-info → ezkit-3.0.1}/PKG-INFO +1 -1
- {ezkit-3.0.0 → ezkit-3.0.1}/ezKit/database.py +19 -5
- {ezkit-3.0.0 → ezkit-3.0.1/ezKit.egg-info}/PKG-INFO +1 -1
- {ezkit-3.0.0 → ezkit-3.0.1}/setup.py +1 -1
- {ezkit-3.0.0 → ezkit-3.0.1}/LICENSE +0 -0
- {ezkit-3.0.0 → ezkit-3.0.1}/MANIFEST.in +0 -0
- {ezkit-3.0.0 → ezkit-3.0.1}/README.md +0 -0
- {ezkit-3.0.0 → ezkit-3.0.1}/ezKit/__init__.py +0 -0
- {ezkit-3.0.0 → ezkit-3.0.1}/ezKit/utils.py +0 -0
- {ezkit-3.0.0 → ezkit-3.0.1}/ezKit.egg-info/SOURCES.txt +0 -0
- {ezkit-3.0.0 → ezkit-3.0.1}/ezKit.egg-info/dependency_links.txt +0 -0
- {ezkit-3.0.0 → ezkit-3.0.1}/ezKit.egg-info/requires.txt +0 -0
- {ezkit-3.0.0 → ezkit-3.0.1}/ezKit.egg-info/top_level.txt +0 -0
- {ezkit-3.0.0 → ezkit-3.0.1}/pyproject.toml +0 -0
- {ezkit-3.0.0 → ezkit-3.0.1}/setup.cfg +0 -0
|
@@ -26,7 +26,8 @@ class Database:
|
|
|
26
26
|
|
|
27
27
|
@contextmanager
|
|
28
28
|
def _get_db(self):
|
|
29
|
-
"""
|
|
29
|
+
"""common database connection context manager"""
|
|
30
|
+
# 公用数据库连接上下文管理器
|
|
30
31
|
session = self._db_session()
|
|
31
32
|
try:
|
|
32
33
|
yield session # 将 session 传递给 with 语句
|
|
@@ -37,13 +38,26 @@ class Database:
|
|
|
37
38
|
finally:
|
|
38
39
|
session.close()
|
|
39
40
|
|
|
40
|
-
def execute(
|
|
41
|
+
def execute(
|
|
42
|
+
self,
|
|
43
|
+
statement: str | TextClause | Delete | Insert | Select | Update, # SQL 语句
|
|
44
|
+
scalars: bool = False, # 是否使用 scalars() 方法获取结果
|
|
45
|
+
) -> CursorResult | ScalarResult | None:
|
|
41
46
|
"""database execute statement"""
|
|
42
47
|
|
|
43
|
-
# SQL
|
|
48
|
+
# statement 可以是 纯 SQL 字符串, 也可以是 text() 对象, 也可以是 ORM 构建的 statement 对象
|
|
44
49
|
#
|
|
45
|
-
# text()
|
|
46
|
-
#
|
|
50
|
+
# str: 会使用 text() 转换为 text() 对象
|
|
51
|
+
# TextClause: 已经处理好的 text() 对象, 可以直接使用
|
|
52
|
+
# Select, Insert, Update, Delete: ORM 构建的 statement 对象
|
|
53
|
+
#
|
|
54
|
+
# scalars: 是否使用 scalars() 方法获取结果, 适用于获取单列数据, 如果是多列数据, 使用 execute() 方法获取结果
|
|
55
|
+
#
|
|
56
|
+
# 返回值:
|
|
57
|
+
#
|
|
58
|
+
# CursorResult: 返回 CursorResult 对象
|
|
59
|
+
# ScalarResult: 返回 ScalarResult 对象
|
|
60
|
+
# None: 如果发生错误, 则返回 None
|
|
47
61
|
|
|
48
62
|
info: str = "database execute statement"
|
|
49
63
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|