database-smartools 1.0.0__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.
- database-smartools/__init__.py +18 -0
- database-smartools/api/__init__.py +18 -0
- database-smartools/api/etl.py +160 -0
- database-smartools/database/__init__.py +18 -0
- database-smartools/database/dameng_extend.py +65 -0
- database-smartools/database/db_handler.py +676 -0
- database-smartools/database/mysql_extend.py +396 -0
- database-smartools/database/oceanbase_extend.py +55 -0
- database-smartools/database/oracle_extend.py +27 -0
- database-smartools/database/postgre_extend.py +396 -0
- database-smartools/main.py +86 -0
- database-smartools/module/__init__.py +18 -0
- database-smartools/module/function.py +115 -0
- database-smartools/utils/__init__.py +18 -0
- database-smartools/utils/config.py +56 -0
- database-smartools/utils/debug.py +72 -0
- database-smartools/utils/file.py +42 -0
- database-smartools/utils/http.py +74 -0
- database-smartools/utils/logger.py +237 -0
- database-smartools/utils/output.py +31 -0
- database-smartools/utils/texter.py +186 -0
- database-smartools/utils/timer.py +52 -0
- database-tools/__init__.py +18 -0
- database-tools/api/__init__.py +18 -0
- database-tools/api/etl.py +160 -0
- database-tools/database/__init__.py +18 -0
- database-tools/database/dameng_extend.py +65 -0
- database-tools/database/db_handler.py +676 -0
- database-tools/database/mysql_extend.py +396 -0
- database-tools/database/oceanbase_extend.py +55 -0
- database-tools/database/oracle_extend.py +27 -0
- database-tools/database/postgre_extend.py +396 -0
- database-tools/main.py +86 -0
- database-tools/module/__init__.py +18 -0
- database-tools/module/function.py +115 -0
- database-tools/utils/__init__.py +18 -0
- database-tools/utils/config.py +56 -0
- database-tools/utils/debug.py +72 -0
- database-tools/utils/file.py +42 -0
- database-tools/utils/http.py +74 -0
- database-tools/utils/logger.py +237 -0
- database-tools/utils/output.py +31 -0
- database-tools/utils/texter.py +186 -0
- database-tools/utils/timer.py +52 -0
- database_smartools-1.0.0.dist-info/METADATA +84 -0
- database_smartools-1.0.0.dist-info/RECORD +50 -0
- database_smartools-1.0.0.dist-info/WHEEL +5 -0
- database_smartools-1.0.0.dist-info/licenses/LICENSE +13 -0
- database_smartools-1.0.0.dist-info/top_level.txt +1 -0
- model/__init__.py +12 -0
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
"""
|
3
|
+
@项目名称 : yhfin-data-agent
|
4
|
+
@文件名称 : __init__.py.py
|
5
|
+
@创建人 : zhongbinjie
|
6
|
+
@创建时间 : 2025/9/9 17:02
|
7
|
+
@文件说明 :
|
8
|
+
@企业名称 : 深圳市赢和信息技术有限公司
|
9
|
+
@Copyright:2025-2035, 深圳市赢和信息技术有限公司. All rights Reserved.
|
10
|
+
"""
|
11
|
+
|
12
|
+
|
13
|
+
def test():
|
14
|
+
print()
|
15
|
+
|
16
|
+
|
17
|
+
if __name__ == '__main__':
|
18
|
+
None
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
"""
|
3
|
+
@项目名称 : yhfin-data-agent
|
4
|
+
@文件名称 : __init__.py.py
|
5
|
+
@创建人 : zhongbinjie
|
6
|
+
@创建时间 : 2025/9/9 17:02
|
7
|
+
@文件说明 :
|
8
|
+
@企业名称 : 深圳市赢和信息技术有限公司
|
9
|
+
@Copyright:2025-2035, 深圳市赢和信息技术有限公司. All rights Reserved.
|
10
|
+
"""
|
11
|
+
|
12
|
+
|
13
|
+
def test():
|
14
|
+
print()
|
15
|
+
|
16
|
+
|
17
|
+
if __name__ == '__main__':
|
18
|
+
None
|
@@ -0,0 +1,160 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
"""
|
3
|
+
@项目名称 : python-main
|
4
|
+
@文件名称 : etl.py
|
5
|
+
@创建人 : zhongbinjie
|
6
|
+
@创建时间 : 2025/6/7 19:06
|
7
|
+
@文件说明 :
|
8
|
+
@企业名称 : 深圳市赢和信息技术有限公司
|
9
|
+
@Copyright:2025-2035, 深圳市赢和信息技术有限公司. All rights Reserved.
|
10
|
+
"""
|
11
|
+
|
12
|
+
from fastapi import APIRouter
|
13
|
+
from utils import logger, http
|
14
|
+
import json
|
15
|
+
from module import function as func
|
16
|
+
from database import db_handler as dh
|
17
|
+
|
18
|
+
router = APIRouter()
|
19
|
+
|
20
|
+
#mcp function call格式
|
21
|
+
"""
|
22
|
+
模板样例:
|
23
|
+
[
|
24
|
+
{
|
25
|
+
"id": "call_xxxx", #必填项
|
26
|
+
"type": "function", #必填项
|
27
|
+
"function": {
|
28
|
+
"name": "", #必填项
|
29
|
+
"description": "", #必填项,简要描述
|
30
|
+
"script_path": "", #选填项
|
31
|
+
"input_schema": { #选填项,可以没有参数列表
|
32
|
+
"title": "xxxxx_arguments", #如果有参数列表,则必填项
|
33
|
+
"type": "object", #如果有参数列表,则必填项
|
34
|
+
"properties": {
|
35
|
+
"arg1": {"type" : '', "value" : ''}, #如果有参数列表,则必填项,结构保持一致
|
36
|
+
"arg2": {"type" : '', "value" : ''}
|
37
|
+
},
|
38
|
+
"required": [
|
39
|
+
"arg1" #required为选填项,指properties里有的参数为必选参数,值不能为空
|
40
|
+
]
|
41
|
+
}
|
42
|
+
}
|
43
|
+
}
|
44
|
+
]
|
45
|
+
实际样例:
|
46
|
+
[
|
47
|
+
{
|
48
|
+
"id": "wf_pytest",
|
49
|
+
"type": "function",
|
50
|
+
"function": {
|
51
|
+
"name": "py_test2",
|
52
|
+
"description": "Function for testing purposes",
|
53
|
+
"script_path": "",
|
54
|
+
"input_schema": {
|
55
|
+
"title": "pytest_arguments",
|
56
|
+
"type": "object",
|
57
|
+
"properties": {
|
58
|
+
"db_key" : {
|
59
|
+
"type": "string",
|
60
|
+
"value": "123"
|
61
|
+
},
|
62
|
+
"p_beg_date": {
|
63
|
+
"type": "string",
|
64
|
+
"value": "20180101"
|
65
|
+
},
|
66
|
+
"p_end_date": {
|
67
|
+
"type": "string",
|
68
|
+
"value": "20180131"
|
69
|
+
},
|
70
|
+
"p_cal_code": {
|
71
|
+
"type": "string",
|
72
|
+
"value": "400007"
|
73
|
+
}
|
74
|
+
},
|
75
|
+
"required": [
|
76
|
+
"db_key",
|
77
|
+
"p_beg_date",
|
78
|
+
"p_end_date"
|
79
|
+
]
|
80
|
+
}
|
81
|
+
}
|
82
|
+
}
|
83
|
+
]
|
84
|
+
"""
|
85
|
+
@router.get("/functionCall")
|
86
|
+
def function_call(function_str: str):
|
87
|
+
return_list = []
|
88
|
+
#支持工作流:任务1>>任务2串联方式
|
89
|
+
try:
|
90
|
+
function_map = json.loads(function_str)
|
91
|
+
for function in function_map:
|
92
|
+
workflow_id = function['id']
|
93
|
+
sub_functions = function['function']['name'].split('>>')
|
94
|
+
properties = function['function']['input_schema']['properties']
|
95
|
+
requires = function['function']['input_schema']['required']
|
96
|
+
script_path = None
|
97
|
+
if 'script_path' in function['function'].keys():
|
98
|
+
script_path = function['function']['script_path']
|
99
|
+
args = {}
|
100
|
+
for key, param in properties.items():
|
101
|
+
if key in requires and (not param['value'] or param['value'] == ""):
|
102
|
+
message = f"缺少必要参数:{key}"
|
103
|
+
logger.error(message)
|
104
|
+
return http.ResponseUtil.error(message=message)
|
105
|
+
args[key] = param['value']
|
106
|
+
|
107
|
+
for sub in sub_functions:
|
108
|
+
rtn_map = func.execute_function(sub, args, script_path)
|
109
|
+
exec_time = rtn_map['time']
|
110
|
+
if not rtn_map['status']:
|
111
|
+
return_list.append(http.ResponseUtil.error(message=rtn_map['message'], workflow_id=workflow_id, function=sub, exec_time=exec_time))
|
112
|
+
else:
|
113
|
+
data = rtn_map['data']
|
114
|
+
return_list.append(http.ResponseUtil.success(data=data, workflow_id=workflow_id, function=sub, exec_time=exec_time))
|
115
|
+
|
116
|
+
except json.JSONDecodeError:
|
117
|
+
message = f"json格式异常,请检查参数:{function_str}"
|
118
|
+
logger.error(message)
|
119
|
+
return_list.append(http.ResponseUtil.error(message=message))
|
120
|
+
return http.ResponseUtil.error(message=message)
|
121
|
+
|
122
|
+
return return_list
|
123
|
+
|
124
|
+
@router.get("/dbpool/refresh")
|
125
|
+
def refresh_dbpool(db_key: str):
|
126
|
+
if db_key:
|
127
|
+
if db_key not in dh.POOL_MAP.keys():
|
128
|
+
return http.ResponseUtil.error(message=f'刷新失败,数据池中没有{db_key}对应的连接')
|
129
|
+
else:
|
130
|
+
pool, message = dh.get_pool_by_key(db_key, refresh=True)
|
131
|
+
if not pool:
|
132
|
+
return http.ResponseUtil.error(message=message)
|
133
|
+
|
134
|
+
return http.ResponseUtil.success(message=f"数据库连接池刷新成功,db_key: {db_key}")
|
135
|
+
|
136
|
+
@router.get("/logs")
|
137
|
+
def grap_log(id: str = None):
|
138
|
+
message_id = id
|
139
|
+
log_file = logger.LOG_NAME
|
140
|
+
logs = []
|
141
|
+
with open(log_file, "r", encoding="utf-8") as file:
|
142
|
+
for line in file:
|
143
|
+
try:
|
144
|
+
log = json.loads(line.strip())
|
145
|
+
if log['id'] == message_id and message_id is not None:
|
146
|
+
logs.append(log)
|
147
|
+
if not message_id:
|
148
|
+
logs.append(log)
|
149
|
+
|
150
|
+
except json.JSONDecodeError:
|
151
|
+
None
|
152
|
+
logger.info(f"抓取日志信息成功,message_id:{id}")
|
153
|
+
return http.ResponseUtil.success(data={'logs' : logs})
|
154
|
+
|
155
|
+
def test():
|
156
|
+
print()
|
157
|
+
|
158
|
+
|
159
|
+
if __name__ == '__main__':
|
160
|
+
None
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
"""
|
3
|
+
@项目名称 : yhfin-data-agent
|
4
|
+
@文件名称 : __init__.py.py
|
5
|
+
@创建人 : zhongbinjie
|
6
|
+
@创建时间 : 2025/9/9 17:02
|
7
|
+
@文件说明 :
|
8
|
+
@企业名称 : 深圳市赢和信息技术有限公司
|
9
|
+
@Copyright:2025-2035, 深圳市赢和信息技术有限公司. All rights Reserved.
|
10
|
+
"""
|
11
|
+
|
12
|
+
|
13
|
+
def test():
|
14
|
+
print()
|
15
|
+
|
16
|
+
|
17
|
+
if __name__ == '__main__':
|
18
|
+
None
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
"""
|
3
|
+
@项目名称 : python-main
|
4
|
+
@文件名称 : oracle_extend.py
|
5
|
+
@创建人 : zhongbinjie
|
6
|
+
@创建时间 : 2025/7/2 16:14
|
7
|
+
@文件说明 :
|
8
|
+
@企业名称 : 深圳市赢和信息技术有限公司
|
9
|
+
@Copyright:2025-2035, 深圳市赢和信息技术有限公司. All rights Reserved.
|
10
|
+
"""
|
11
|
+
import dmPython
|
12
|
+
from datetime import date, datetime, timedelta
|
13
|
+
from decimal import Decimal
|
14
|
+
|
15
|
+
|
16
|
+
def formatter(result):
|
17
|
+
data = []
|
18
|
+
for row in result["data"]:
|
19
|
+
item_map = {}
|
20
|
+
for index, item in enumerate(row):
|
21
|
+
column_type = result["desc"][index][1]
|
22
|
+
if item is not None:
|
23
|
+
if column_type == dmPython.BOOLEAN:
|
24
|
+
# 将达梦 BOOLEAN 类型转换为 Python bool 类型
|
25
|
+
item = bool(item)
|
26
|
+
elif column_type == dmPython.BINARY:
|
27
|
+
# 将达梦 BINARY 类型转换为 Python bytes 类型
|
28
|
+
item = bytes(item)
|
29
|
+
elif column_type == dmPython.DATE:
|
30
|
+
# 将达梦 DATE 类型转换为 Python datetime.date 类型
|
31
|
+
item = datetime(item.year, item.month, item.day)
|
32
|
+
elif column_type == dmPython.TIMESTAMP:
|
33
|
+
# 将达梦 TIMESTAMP 类型转换为 Python datetime.datetime 类型
|
34
|
+
item = datetime(
|
35
|
+
item.year,
|
36
|
+
item.month,
|
37
|
+
item.day,
|
38
|
+
item.hour,
|
39
|
+
item.minute,
|
40
|
+
item.second,
|
41
|
+
item.microsecond,
|
42
|
+
)
|
43
|
+
elif column_type == dmPython.INTERVAL:
|
44
|
+
# 将达梦 INTERVAL 类型转换为 Python datetime.timedelta 类型
|
45
|
+
item = timedelta(
|
46
|
+
days=item.days,
|
47
|
+
seconds=item.seconds,
|
48
|
+
microseconds=item.microseconds,
|
49
|
+
)
|
50
|
+
elif column_type == dmPython.DECIMAL:
|
51
|
+
# 将达梦 DECIMAL 类型转换为 Python decimal.Decimal 类型
|
52
|
+
item = float(item)
|
53
|
+
elif column_type == dmPython.REAL:
|
54
|
+
# 将达梦 REAL 类型转换为 Python float 类型
|
55
|
+
item = float(item)
|
56
|
+
elif column_type == dmPython.BIGINT:
|
57
|
+
# 将达梦 BIGINT 类型转换为 Python int 类型
|
58
|
+
item = int(item)
|
59
|
+
elif column_type == dmPython.STRING:
|
60
|
+
# 将达梦 STRING 类型转换为 Python str 类型
|
61
|
+
item = str(item)
|
62
|
+
|
63
|
+
item_map[result["desc"][index][0].lower()] = item
|
64
|
+
data.append(item_map)
|
65
|
+
return data
|