ezKit 1.12.3__py3-none-any.whl → 1.12.5__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 +36 -19
- {ezkit-1.12.3.dist-info → ezkit-1.12.5.dist-info}/METADATA +1 -1
- {ezkit-1.12.3.dist-info → ezkit-1.12.5.dist-info}/RECORD +6 -6
- {ezkit-1.12.3.dist-info → ezkit-1.12.5.dist-info}/WHEEL +0 -0
- {ezkit-1.12.3.dist-info → ezkit-1.12.5.dist-info}/licenses/LICENSE +0 -0
- {ezkit-1.12.3.dist-info → ezkit-1.12.5.dist-info}/top_level.txt +0 -0
ezKit/database.py
CHANGED
@@ -13,10 +13,12 @@ from typing import Any, Type
|
|
13
13
|
import pandas as pd
|
14
14
|
from loguru import logger
|
15
15
|
from sqlalchemy import CursorResult, Index, create_engine, text
|
16
|
-
from sqlalchemy.orm import DeclarativeBase, Session
|
16
|
+
from sqlalchemy.orm import DeclarativeBase, Session, declarative_base
|
17
17
|
|
18
18
|
from . import utils
|
19
19
|
|
20
|
+
Base = declarative_base()
|
21
|
+
|
20
22
|
|
21
23
|
class Database:
|
22
24
|
"""Database"""
|
@@ -71,6 +73,17 @@ class Database:
|
|
71
73
|
|
72
74
|
# ----------------------------------------------------------------------------------------------
|
73
75
|
|
76
|
+
def initialization_table(self, table: str):
|
77
|
+
"""初始化表"""
|
78
|
+
|
79
|
+
# 初始化所有表
|
80
|
+
# db.metadata_init(Base)
|
81
|
+
# 初始化指定表
|
82
|
+
# database.metadata_init(Base, tables=[Base.metadata.tables['ashare']])
|
83
|
+
self.metadata_init(Base, tables=[Base.metadata.tables[table]])
|
84
|
+
|
85
|
+
# ----------------------------------------------------------------------------------------------
|
86
|
+
|
74
87
|
def create_index(self, index_name, table_field) -> bool:
|
75
88
|
# 创建索引
|
76
89
|
# https://stackoverflow.com/a/41254430
|
@@ -349,33 +362,37 @@ class Database:
|
|
349
362
|
|
350
363
|
# ----------------------------------------------------------------------------------------------
|
351
364
|
|
352
|
-
def
|
353
|
-
"""
|
365
|
+
def create_data(self, TS: Type, data: list) -> bool:
|
366
|
+
"""创建数据. TS: Table Schema"""
|
354
367
|
|
355
368
|
info: str = "create data"
|
356
369
|
|
357
|
-
|
370
|
+
if not utils.isTrue(data, list):
|
371
|
+
logger.error(f"{info} [data type is not a list]")
|
358
372
|
|
359
|
-
|
373
|
+
logger.info(f"{info} ......")
|
374
|
+
|
375
|
+
with Session(self.engine) as session:
|
376
|
+
|
377
|
+
try:
|
360
378
|
|
361
|
-
|
379
|
+
for item in data:
|
362
380
|
|
363
|
-
|
364
|
-
|
365
|
-
|
381
|
+
if not utils.isTrue(item, dict):
|
382
|
+
logger.error(f"{info} [data type error]")
|
383
|
+
session.rollback()
|
384
|
+
return False
|
366
385
|
|
367
|
-
|
368
|
-
logger.info(f"{info} [data type is list]")
|
369
|
-
for item in data:
|
370
|
-
session.add(TS(**item))
|
386
|
+
session.add(TS(**item))
|
371
387
|
|
372
388
|
session.commit()
|
373
389
|
|
374
|
-
|
390
|
+
logger.success(f"{info} [success]")
|
375
391
|
|
376
|
-
|
392
|
+
return True
|
377
393
|
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
394
|
+
except Exception as e:
|
395
|
+
session.rollback()
|
396
|
+
logger.error(f"{info} [failed]")
|
397
|
+
logger.exception(e)
|
398
|
+
return False
|
@@ -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=aRJGiBOv4_W69MQnwaF0W1wClUFF7HQYYThAvjsRRrk,13679
|
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=VyAw2yEs15VER9RCpMgskx1l0zrSpRlV34X___eOia0,42416
|
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.5.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
19
|
+
ezkit-1.12.5.dist-info/METADATA,sha256=QzYy8GO4rrQpJq82RZ-zmnFtu5xg2gA88Wiup4DJYkM,316
|
20
|
+
ezkit-1.12.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
21
|
+
ezkit-1.12.5.dist-info/top_level.txt,sha256=aYLB_1WODsqNTsTFWcKP-BN0KCTKcV-HZJ4zlHkCFw8,6
|
22
|
+
ezkit-1.12.5.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|