ezKit 1.12.41__py3-none-any.whl → 1.12.43__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 +17 -4
- {ezkit-1.12.41.dist-info → ezkit-1.12.43.dist-info}/METADATA +1 -1
- {ezkit-1.12.41.dist-info → ezkit-1.12.43.dist-info}/RECORD +6 -6
- {ezkit-1.12.41.dist-info → ezkit-1.12.43.dist-info}/WHEEL +0 -0
- {ezkit-1.12.41.dist-info → ezkit-1.12.43.dist-info}/licenses/LICENSE +0 -0
- {ezkit-1.12.41.dist-info → ezkit-1.12.43.dist-info}/top_level.txt +0 -0
ezKit/database.py
CHANGED
@@ -18,14 +18,19 @@ from loguru import logger
|
|
18
18
|
from sqlalchemy import CursorResult, Engine, Index, bindparam, create_engine, insert, text
|
19
19
|
from sqlalchemy.engine import Result
|
20
20
|
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker
|
21
|
-
from sqlalchemy.orm import DeclarativeBase, Session
|
21
|
+
from sqlalchemy.orm import DeclarativeBase, Session
|
22
22
|
|
23
23
|
from . import utils
|
24
24
|
from .errors import database_error, sqlalchemy_error
|
25
25
|
|
26
26
|
# --------------------------------------------------------------------------------------------------
|
27
27
|
|
28
|
-
|
28
|
+
|
29
|
+
class Base(DeclarativeBase):
|
30
|
+
"""所有 ORM 模型的基类"""
|
31
|
+
|
32
|
+
pass # pylint: disable=unnecessary-pass
|
33
|
+
|
29
34
|
|
30
35
|
# --------------------------------------------------------------------------------------------------
|
31
36
|
|
@@ -79,11 +84,19 @@ def orm_object_to_dict(obj, include: list | None = None) -> dict | None:
|
|
79
84
|
data = {}
|
80
85
|
|
81
86
|
for column in obj.__table__.columns:
|
87
|
+
|
82
88
|
key = column.name
|
89
|
+
|
83
90
|
if include and key not in include:
|
84
91
|
continue
|
92
|
+
|
85
93
|
value = getattr(obj, key)
|
86
|
-
|
94
|
+
|
95
|
+
if isinstance(value, str):
|
96
|
+
# 移除字符串前后的空白字符, 包括空格、\n、\t 等
|
97
|
+
data[key] = str(value).strip()
|
98
|
+
elif isinstance(value, (datetime, date)):
|
99
|
+
# 日期时间转换为可读的字符串
|
87
100
|
# data[key] = value.isoformat()
|
88
101
|
data[key] = value.strftime("%Y-%m-%d %H:%M:%S")
|
89
102
|
else:
|
@@ -349,7 +362,7 @@ class Database:
|
|
349
362
|
|
350
363
|
# ----------------------------------------------------------------------------------------------
|
351
364
|
|
352
|
-
def metadata_init(self, base:
|
365
|
+
def metadata_init(self, base: type[Base], **kwargs) -> bool:
|
353
366
|
# https://stackoverflow.com/questions/19175311/how-to-create-only-one-table-with-sqlalchemy
|
354
367
|
info = "Database init table"
|
355
368
|
try:
|
@@ -4,7 +4,7 @@ ezKit/auth.py,sha256=HO19O4qOz68e0YwOP04habxMCAk42B3D7LW7yKgm9ZA,398
|
|
4
4
|
ezKit/bottle.py,sha256=43h4v1kzz6qrLvCt5IMN0H-gFtaT0koG9wETqteXsps,181666
|
5
5
|
ezKit/bottle_extensions.py,sha256=27rogmfK7mL2qUSjXH79IMGZbCVULtYEikql_N9O6Zs,1165
|
6
6
|
ezKit/cipher.py,sha256=7jBarRH7ukSYzkz-Anl8B8JzluhnRz4CLHidPRRj_cg,2939
|
7
|
-
ezKit/database.py,sha256=
|
7
|
+
ezKit/database.py,sha256=i64089rudCHIYOPUOSfrN3h7OJCdP_W8o3zl0WogMFw,32546
|
8
8
|
ezKit/dockerhub.py,sha256=j-wQO-71BsOgExHZhYynuy2k_hCX3on-vg0TH7QCit4,1996
|
9
9
|
ezKit/errors.py,sha256=92PggwPQfTS3Vg4og7GHYnO9CTSM7zmuh2w3kx_tSBE,1425
|
10
10
|
ezKit/fastapix.py,sha256=-nz565ASKvp3nGs9J4wORTHxlhMozqCwv8zREWpmYtI,3382
|
@@ -18,8 +18,8 @@ ezKit/token.py,sha256=Ac-i9xfq4TqpGyfCzakjrh4NYzxHiN2sCQrMk1tzVi8,1716
|
|
18
18
|
ezKit/utils.py,sha256=U457ahFkxIXuB-qWvS3995xJs-LlkFIX5_ZWVgmL5cY,43130
|
19
19
|
ezKit/xftp.py,sha256=-XQXyhMqeigT63P6sXkSS7r4GROXyqqlkzKxITLWG-g,8278
|
20
20
|
ezKit/zabbix.py,sha256=PkMnfu7mcuotwwIIsHaC9FsNg-gap6hD1xvm0AwSL1Y,33777
|
21
|
-
ezkit-1.12.
|
22
|
-
ezkit-1.12.
|
23
|
-
ezkit-1.12.
|
24
|
-
ezkit-1.12.
|
25
|
-
ezkit-1.12.
|
21
|
+
ezkit-1.12.43.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
22
|
+
ezkit-1.12.43.dist-info/METADATA,sha256=oMY1dzYcL1sEjQOD_KbaQ1TMbWaZS9RRahnqN_Qk10A,317
|
23
|
+
ezkit-1.12.43.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
24
|
+
ezkit-1.12.43.dist-info/top_level.txt,sha256=aYLB_1WODsqNTsTFWcKP-BN0KCTKcV-HZJ4zlHkCFw8,6
|
25
|
+
ezkit-1.12.43.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|