ezKit 1.12.21__py3-none-any.whl → 1.12.23__py3-none-any.whl
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/database.py +12 -32
- {ezkit-1.12.21.dist-info → ezkit-1.12.23.dist-info}/METADATA +1 -1
- {ezkit-1.12.21.dist-info → ezkit-1.12.23.dist-info}/RECORD +6 -6
- {ezkit-1.12.21.dist-info → ezkit-1.12.23.dist-info}/WHEEL +0 -0
- {ezkit-1.12.21.dist-info → ezkit-1.12.23.dist-info}/licenses/LICENSE +0 -0
- {ezkit-1.12.21.dist-info → ezkit-1.12.23.dist-info}/top_level.txt +0 -0
ezKit/database.py
CHANGED
@@ -602,12 +602,15 @@ class DatabaseAsyncSession:
|
|
602
602
|
"""Initiation"""
|
603
603
|
self.AsyncSessionLocal = session
|
604
604
|
|
605
|
-
# 执行器
|
606
|
-
|
605
|
+
# 执行器 (CRUD都可以执行. 即可以执行原生SQL, 也可以执行ORM)
|
606
|
+
# statement: SQL 或者 insert(schema)等
|
607
|
+
# params: List[dict]
|
608
|
+
async def operater(self, statement, params: Any | None = None, **kwargs) -> Result | None:
|
607
609
|
|
608
610
|
async with self.AsyncSessionLocal() as session:
|
611
|
+
|
609
612
|
try:
|
610
|
-
result = await session.execute(
|
613
|
+
result = await session.execute(statement, params, **kwargs)
|
611
614
|
await session.commit()
|
612
615
|
return result
|
613
616
|
except Exception as e:
|
@@ -615,40 +618,17 @@ class DatabaseAsyncSession:
|
|
615
618
|
logger.exception(e)
|
616
619
|
return None
|
617
620
|
|
618
|
-
# 精确返回一个标量结果
|
619
|
-
async def operate_return_scalar_one(self,
|
620
|
-
result = await self.operater(
|
621
|
+
# 精确返回一个标量结果 (适用于只返回一行数据的select, 比如 count 查询)
|
622
|
+
async def operate_return_scalar_one(self, statement, params: Any | None = None, **kwargs) -> Any | None:
|
623
|
+
result = await self.operater(statement, params, **kwargs)
|
621
624
|
if result is None:
|
622
625
|
return None
|
623
626
|
return result.scalar_one()
|
624
627
|
|
625
|
-
# 返回所有结果
|
626
|
-
async def operate_return_mappings_all(self,
|
627
|
-
result = await self.operater(
|
628
|
+
# 返回所有结果 (适用于所有select)
|
629
|
+
async def operate_return_mappings_all(self, statement, params: Any | None = None, **kwargs) -> List[Any]:
|
630
|
+
result = await self.operater(statement, params, **kwargs)
|
628
631
|
if result is None:
|
629
632
|
return []
|
630
633
|
rows = result.mappings().all()
|
631
634
|
return [dict(row) for row in rows]
|
632
|
-
|
633
|
-
# 创建数据
|
634
|
-
async def create_with_schema(self, schema: Type[Any], data: List[dict]) -> int:
|
635
|
-
|
636
|
-
if not utils.isTrue(data, list):
|
637
|
-
return 0
|
638
|
-
|
639
|
-
async with self.AsyncSessionLocal() as session:
|
640
|
-
try:
|
641
|
-
# for item in data:
|
642
|
-
# if not utils.isTrue(item, dict):
|
643
|
-
# await session.rollback()
|
644
|
-
# return False
|
645
|
-
# # 这里不使用 await
|
646
|
-
# session.add(schema(**item))
|
647
|
-
stmt = insert(schema)
|
648
|
-
await session.execute(stmt, data)
|
649
|
-
await session.commit()
|
650
|
-
return len(data)
|
651
|
-
except Exception as e:
|
652
|
-
await session.rollback()
|
653
|
-
logger.exception(e)
|
654
|
-
return 0
|
@@ -3,7 +3,7 @@ ezKit/_file.py,sha256=0qRZhwYuagTgTGrhm-tzAMvEQT4HTJA_xZKqF2bo0ho,1207
|
|
3
3
|
ezKit/bottle.py,sha256=43h4v1kzz6qrLvCt5IMN0H-gFtaT0koG9wETqteXsps,181666
|
4
4
|
ezKit/bottle_extensions.py,sha256=27rogmfK7mL2qUSjXH79IMGZbCVULtYEikql_N9O6Zs,1165
|
5
5
|
ezKit/cipher.py,sha256=7jBarRH7ukSYzkz-Anl8B8JzluhnRz4CLHidPRRj_cg,2939
|
6
|
-
ezKit/database.py,sha256=
|
6
|
+
ezKit/database.py,sha256=ZvyxBr-_3XNTuyJTM_5HUJqeyAmLI-ftDAKTyab5wsw,21732
|
7
7
|
ezKit/dockerhub.py,sha256=j-wQO-71BsOgExHZhYynuy2k_hCX3on-vg0TH7QCit4,1996
|
8
8
|
ezKit/http.py,sha256=zhNxJF-x91UqGncXWxVXnhZVpFo_wmmpGnMXVT11y9E,1832
|
9
9
|
ezKit/markdown_to_html.template,sha256=21G2sSVGJn6aJvHd0NN4zY5YiDteKe4UtW36AzBwSdk,22274
|
@@ -15,8 +15,8 @@ ezKit/token.py,sha256=Ac-i9xfq4TqpGyfCzakjrh4NYzxHiN2sCQrMk1tzVi8,1716
|
|
15
15
|
ezKit/utils.py,sha256=U457ahFkxIXuB-qWvS3995xJs-LlkFIX5_ZWVgmL5cY,43130
|
16
16
|
ezKit/xftp.py,sha256=-XQXyhMqeigT63P6sXkSS7r4GROXyqqlkzKxITLWG-g,8278
|
17
17
|
ezKit/zabbix.py,sha256=PkMnfu7mcuotwwIIsHaC9FsNg-gap6hD1xvm0AwSL1Y,33777
|
18
|
-
ezkit-1.12.
|
19
|
-
ezkit-1.12.
|
20
|
-
ezkit-1.12.
|
21
|
-
ezkit-1.12.
|
22
|
-
ezkit-1.12.
|
18
|
+
ezkit-1.12.23.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
19
|
+
ezkit-1.12.23.dist-info/METADATA,sha256=_uyFQwYed7tO-PoyfSnn5cEAQAz7lHU5thsZaegrOfo,317
|
20
|
+
ezkit-1.12.23.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
21
|
+
ezkit-1.12.23.dist-info/top_level.txt,sha256=aYLB_1WODsqNTsTFWcKP-BN0KCTKcV-HZJ4zlHkCFw8,6
|
22
|
+
ezkit-1.12.23.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|