ezKit 1.12.2__tar.gz → 1.12.4__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.2/ezKit.egg-info → ezkit-1.12.4}/PKG-INFO +1 -1
  2. {ezkit-1.12.2 → ezkit-1.12.4}/ezKit/database.py +48 -2
  3. {ezkit-1.12.2 → ezkit-1.12.4/ezKit.egg-info}/PKG-INFO +1 -1
  4. {ezkit-1.12.2 → ezkit-1.12.4}/setup.py +1 -1
  5. {ezkit-1.12.2 → ezkit-1.12.4}/LICENSE +0 -0
  6. {ezkit-1.12.2 → ezkit-1.12.4}/MANIFEST.in +0 -0
  7. {ezkit-1.12.2 → ezkit-1.12.4}/README.md +0 -0
  8. {ezkit-1.12.2 → ezkit-1.12.4}/ezKit/__init__.py +0 -0
  9. {ezkit-1.12.2 → ezkit-1.12.4}/ezKit/_file.py +0 -0
  10. {ezkit-1.12.2 → ezkit-1.12.4}/ezKit/bottle.py +0 -0
  11. {ezkit-1.12.2 → ezkit-1.12.4}/ezKit/bottle_extensions.py +0 -0
  12. {ezkit-1.12.2 → ezkit-1.12.4}/ezKit/cipher.py +0 -0
  13. {ezkit-1.12.2 → ezkit-1.12.4}/ezKit/dockerhub.py +0 -0
  14. {ezkit-1.12.2 → ezkit-1.12.4}/ezKit/http.py +0 -0
  15. {ezkit-1.12.2 → ezkit-1.12.4}/ezKit/markdown_to_html.template +0 -0
  16. {ezkit-1.12.2 → ezkit-1.12.4}/ezKit/mongo.py +0 -0
  17. {ezkit-1.12.2 → ezkit-1.12.4}/ezKit/qywx.py +0 -0
  18. {ezkit-1.12.2 → ezkit-1.12.4}/ezKit/redis.py +0 -0
  19. {ezkit-1.12.2 → ezkit-1.12.4}/ezKit/sendemail.py +0 -0
  20. {ezkit-1.12.2 → ezkit-1.12.4}/ezKit/token.py +0 -0
  21. {ezkit-1.12.2 → ezkit-1.12.4}/ezKit/utils.py +0 -0
  22. {ezkit-1.12.2 → ezkit-1.12.4}/ezKit/xftp.py +0 -0
  23. {ezkit-1.12.2 → ezkit-1.12.4}/ezKit/zabbix.py +0 -0
  24. {ezkit-1.12.2 → ezkit-1.12.4}/ezKit.egg-info/SOURCES.txt +0 -0
  25. {ezkit-1.12.2 → ezkit-1.12.4}/ezKit.egg-info/dependency_links.txt +0 -0
  26. {ezkit-1.12.2 → ezkit-1.12.4}/ezKit.egg-info/requires.txt +0 -0
  27. {ezkit-1.12.2 → ezkit-1.12.4}/ezKit.egg-info/top_level.txt +0 -0
  28. {ezkit-1.12.2 → ezkit-1.12.4}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ezKit
3
- Version: 1.12.2
3
+ Version: 1.12.4
4
4
  Summary: Easy Kit
5
5
  Author: septvean
6
6
  Author-email: septvean@gmail.com
@@ -8,15 +8,17 @@
8
8
  # https://www.postgresql.org/docs/14/datatype.html
9
9
  import csv
10
10
  import json
11
- from typing import Any
11
+ from typing import Any, Type
12
12
 
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
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
@@ -346,3 +359,36 @@ class Database:
346
359
  logger.error(f"{info} [failed]")
347
360
  logger.exception(e)
348
361
  return data
362
+
363
+ # ----------------------------------------------------------------------------------------------
364
+
365
+ def create_with_dict_or_list(self, TS: Type, data: dict | list):
366
+ """将 dict 或 list 类型的数据添加到表中. TS: Table Schema"""
367
+
368
+ info: str = "create data"
369
+
370
+ try:
371
+
372
+ logger.info(f"{info} ......")
373
+
374
+ with Session(self.engine) as session:
375
+
376
+ if utils.isTrue(data, dict):
377
+ logger.info(f"{info} [data type is dict]")
378
+ session.add(TS(**data)) # type: ignore
379
+
380
+ if utils.isTrue(data, list):
381
+ logger.info(f"{info} [data type is list]")
382
+ for item in data:
383
+ session.add(TS(**item))
384
+
385
+ session.commit()
386
+
387
+ logger.success(f"{info} [success]")
388
+
389
+ return True
390
+
391
+ except Exception as e:
392
+ logger.error(f"{info} [failed]")
393
+ logger.exception(e)
394
+ return False
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ezKit
3
- Version: 1.12.2
3
+ Version: 1.12.4
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.2",
7
+ version="1.12.4",
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