ezKit 1.12.20__tar.gz → 1.12.22__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 (28) hide show
  1. {ezkit-1.12.20/ezKit.egg-info → ezkit-1.12.22}/PKG-INFO +1 -1
  2. {ezkit-1.12.20 → ezkit-1.12.22}/ezKit/database.py +14 -33
  3. {ezkit-1.12.20 → ezkit-1.12.22/ezKit.egg-info}/PKG-INFO +1 -1
  4. {ezkit-1.12.20 → ezkit-1.12.22}/setup.py +1 -1
  5. {ezkit-1.12.20 → ezkit-1.12.22}/LICENSE +0 -0
  6. {ezkit-1.12.20 → ezkit-1.12.22}/MANIFEST.in +0 -0
  7. {ezkit-1.12.20 → ezkit-1.12.22}/README.md +0 -0
  8. {ezkit-1.12.20 → ezkit-1.12.22}/ezKit/__init__.py +0 -0
  9. {ezkit-1.12.20 → ezkit-1.12.22}/ezKit/_file.py +0 -0
  10. {ezkit-1.12.20 → ezkit-1.12.22}/ezKit/bottle.py +0 -0
  11. {ezkit-1.12.20 → ezkit-1.12.22}/ezKit/bottle_extensions.py +0 -0
  12. {ezkit-1.12.20 → ezkit-1.12.22}/ezKit/cipher.py +0 -0
  13. {ezkit-1.12.20 → ezkit-1.12.22}/ezKit/dockerhub.py +0 -0
  14. {ezkit-1.12.20 → ezkit-1.12.22}/ezKit/http.py +0 -0
  15. {ezkit-1.12.20 → ezkit-1.12.22}/ezKit/markdown_to_html.template +0 -0
  16. {ezkit-1.12.20 → ezkit-1.12.22}/ezKit/mongo.py +0 -0
  17. {ezkit-1.12.20 → ezkit-1.12.22}/ezKit/qywx.py +0 -0
  18. {ezkit-1.12.20 → ezkit-1.12.22}/ezKit/redis.py +0 -0
  19. {ezkit-1.12.20 → ezkit-1.12.22}/ezKit/sendemail.py +0 -0
  20. {ezkit-1.12.20 → ezkit-1.12.22}/ezKit/token.py +0 -0
  21. {ezkit-1.12.20 → ezkit-1.12.22}/ezKit/utils.py +0 -0
  22. {ezkit-1.12.20 → ezkit-1.12.22}/ezKit/xftp.py +0 -0
  23. {ezkit-1.12.20 → ezkit-1.12.22}/ezKit/zabbix.py +0 -0
  24. {ezkit-1.12.20 → ezkit-1.12.22}/ezKit.egg-info/SOURCES.txt +0 -0
  25. {ezkit-1.12.20 → ezkit-1.12.22}/ezKit.egg-info/dependency_links.txt +0 -0
  26. {ezkit-1.12.20 → ezkit-1.12.22}/ezKit.egg-info/requires.txt +0 -0
  27. {ezkit-1.12.20 → ezkit-1.12.22}/ezKit.egg-info/top_level.txt +0 -0
  28. {ezkit-1.12.20 → ezkit-1.12.22}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ezKit
3
- Version: 1.12.20
3
+ Version: 1.12.22
4
4
  Summary: Easy Kit
5
5
  Author: septvean
6
6
  Author-email: septvean@gmail.com
@@ -10,11 +10,11 @@
10
10
  import csv
11
11
  import json
12
12
  from datetime import date, datetime
13
- from typing import Any, Dict, Optional, Tuple, Type
13
+ from typing import Any, Dict, List, Optional, Tuple, Type
14
14
 
15
15
  import pandas as pd
16
16
  from loguru import logger
17
- from sqlalchemy import CursorResult, Engine, Index, bindparam, create_engine, text
17
+ from sqlalchemy import CursorResult, Engine, Index, bindparam, create_engine, insert, text
18
18
  from sqlalchemy.engine import Result
19
19
  from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker
20
20
  from sqlalchemy.orm import DeclarativeBase, Session, declarative_base
@@ -602,13 +602,15 @@ class DatabaseAsyncSession:
602
602
  """Initiation"""
603
603
  self.AsyncSessionLocal = session
604
604
 
605
- # 执行器
606
- async def operater(self, stmt, params, **kwargs) -> Result | None:
605
+ # 执行器 (CRUD都可以执行. 即可以执行原生SQL, 也可以执行ORM)
606
+ # statement: SQL 或者 insert(schema)
607
+ # params: List[dict]
608
+ async def operater(self, statement, params, **kwargs) -> Result | None:
607
609
 
608
610
  async with self.AsyncSessionLocal() as session:
611
+
609
612
  try:
610
- await session.begin()
611
- result = await session.execute(stmt, params, **kwargs)
613
+ result = await session.execute(statement, params, **kwargs)
612
614
  await session.commit()
613
615
  return result
614
616
  except Exception as e:
@@ -616,38 +618,17 @@ class DatabaseAsyncSession:
616
618
  logger.exception(e)
617
619
  return None
618
620
 
619
- # 精确返回一个标量结果
620
- async def operate_return_scalar_one(self, stmt, params, **kwargs) -> Any | None:
621
- result = await self.operater(stmt, params, **kwargs)
621
+ # 精确返回一个标量结果 (适用于只返回一行数据的select, 比如 count 查询)
622
+ async def operate_return_scalar_one(self, statement, params, **kwargs) -> Any | None:
623
+ result = await self.operater(statement, params, **kwargs)
622
624
  if result is None:
623
625
  return None
624
626
  return result.scalar_one()
625
627
 
626
- # 返回所有结果
627
- async def operate_return_mappings_all(self, stmt, params, **kwargs) -> list:
628
- result = await self.operater(stmt, params, **kwargs)
628
+ # 返回所有结果 (适用于所有select)
629
+ async def operate_return_mappings_all(self, statement, params, **kwargs) -> List[Any]:
630
+ result = await self.operater(statement, params, **kwargs)
629
631
  if result is None:
630
632
  return []
631
633
  rows = result.mappings().all()
632
634
  return [dict(row) for row in rows]
633
-
634
- # 创建数据
635
- async def create_with_schema(self, schema: Type, data: list) -> bool:
636
-
637
- if not utils.isTrue(data, list):
638
- return False
639
-
640
- async with self.AsyncSessionLocal() as session:
641
- try:
642
- for item in data:
643
- if not utils.isTrue(item, dict):
644
- await session.rollback()
645
- return False
646
- # 这里不使用 await
647
- session.add(schema(**item))
648
- await session.commit()
649
- return True
650
- except Exception as e:
651
- await session.rollback()
652
- logger.exception(e)
653
- return False
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ezKit
3
- Version: 1.12.20
3
+ Version: 1.12.22
4
4
  Summary: Easy Kit
5
5
  Author: septvean
6
6
  Author-email: septvean@gmail.com
@@ -4,7 +4,7 @@ from setuptools import find_packages, setup
4
4
 
5
5
  setup(
6
6
  name="ezKit",
7
- version="1.12.20",
7
+ version="1.12.22",
8
8
  author="septvean",
9
9
  author_email="septvean@gmail.com",
10
10
  description="Easy Kit",
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
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes