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.
- {ezkit-1.12.20/ezKit.egg-info → ezkit-1.12.22}/PKG-INFO +1 -1
- {ezkit-1.12.20 → ezkit-1.12.22}/ezKit/database.py +14 -33
- {ezkit-1.12.20 → ezkit-1.12.22/ezKit.egg-info}/PKG-INFO +1 -1
- {ezkit-1.12.20 → ezkit-1.12.22}/setup.py +1 -1
- {ezkit-1.12.20 → ezkit-1.12.22}/LICENSE +0 -0
- {ezkit-1.12.20 → ezkit-1.12.22}/MANIFEST.in +0 -0
- {ezkit-1.12.20 → ezkit-1.12.22}/README.md +0 -0
- {ezkit-1.12.20 → ezkit-1.12.22}/ezKit/__init__.py +0 -0
- {ezkit-1.12.20 → ezkit-1.12.22}/ezKit/_file.py +0 -0
- {ezkit-1.12.20 → ezkit-1.12.22}/ezKit/bottle.py +0 -0
- {ezkit-1.12.20 → ezkit-1.12.22}/ezKit/bottle_extensions.py +0 -0
- {ezkit-1.12.20 → ezkit-1.12.22}/ezKit/cipher.py +0 -0
- {ezkit-1.12.20 → ezkit-1.12.22}/ezKit/dockerhub.py +0 -0
- {ezkit-1.12.20 → ezkit-1.12.22}/ezKit/http.py +0 -0
- {ezkit-1.12.20 → ezkit-1.12.22}/ezKit/markdown_to_html.template +0 -0
- {ezkit-1.12.20 → ezkit-1.12.22}/ezKit/mongo.py +0 -0
- {ezkit-1.12.20 → ezkit-1.12.22}/ezKit/qywx.py +0 -0
- {ezkit-1.12.20 → ezkit-1.12.22}/ezKit/redis.py +0 -0
- {ezkit-1.12.20 → ezkit-1.12.22}/ezKit/sendemail.py +0 -0
- {ezkit-1.12.20 → ezkit-1.12.22}/ezKit/token.py +0 -0
- {ezkit-1.12.20 → ezkit-1.12.22}/ezKit/utils.py +0 -0
- {ezkit-1.12.20 → ezkit-1.12.22}/ezKit/xftp.py +0 -0
- {ezkit-1.12.20 → ezkit-1.12.22}/ezKit/zabbix.py +0 -0
- {ezkit-1.12.20 → ezkit-1.12.22}/ezKit.egg-info/SOURCES.txt +0 -0
- {ezkit-1.12.20 → ezkit-1.12.22}/ezKit.egg-info/dependency_links.txt +0 -0
- {ezkit-1.12.20 → ezkit-1.12.22}/ezKit.egg-info/requires.txt +0 -0
- {ezkit-1.12.20 → ezkit-1.12.22}/ezKit.egg-info/top_level.txt +0 -0
- {ezkit-1.12.20 → ezkit-1.12.22}/setup.cfg +0 -0
@@ -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
|
-
|
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.
|
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,
|
621
|
-
result = await self.operater(
|
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,
|
628
|
-
result = await self.operater(
|
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
|
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
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|