@@ -66,6 +66,48 @@ def langsearch(query, apikey):
66
66
else:
67
67
raise Exception(f"API请求失败: {response.status_code}, 错误信息: {response.text}")
68
68
return (response.text)', '{"{\\ "name\\ ": \\ "query\\ ", \\ "type\\ ": \\ "string\\ ", \\ "source\\ ": \\ "reference\\ ", \\ "is_required\\ ": true}"}', 'f0dd8f71-e4ee-11ee-8c84-a8a1595801ab', TRUE, 'PUBLIC', 'INTERNAL', '/src/assets/fx/langsearch/icon.png', '[{"attrs": {"type": "password", "maxlength": 200, "minlength": 1, "show-password": true, "show-word-limit": true}, "field": "apikey", "label": "apikey", "required": true, "input_type": "PasswordInput", "props_info": {"rules": [{"message": "apikey 为必填属性", "required": true}, {"max": 200, "min": 1, "message": "apikey长度在 1 到 200 个字符", "trigger": "blur"}]}, "default_value": "x", "show_default_value": false}]', '', NULL);
69
+ INSERT INTO function_lib (create_time, update_time, id, name, "desc", code, input_field_list, user_id, is_active, permission_type, function_type, icon, init_field_list, init_params, template_id) VALUES ('2025-03-17 08:16:32.626245 +00:00', '2025-03-17 08:16:32.626308 +00:00', '22c21b76-0308-11f0-9694-5618c4394482', 'MySQL 查询', '', e'
70
+ def query_mysql(host,port, user, password, database, sql):
71
+ import pymysql
72
+ import json
73
+ from pymysql.cursors import DictCursor
74
+
75
+ try:
76
+ # 创建连接
77
+ db = pymysql.connect(
78
+ host=host,
79
+ port=int(port),
80
+ user=user,
81
+ password=password,
82
+ database=database,
83
+ cursorclass=DictCursor # 使用字典游标
84
+ )
85
+
86
+ # 使用 cursor() 方法创建一个游标对象 cursor
87
+ cursor = db.cursor()
88
+
89
+ # 使用 execute() 方法执行 SQL 查询
90
+ cursor.execute(sql)
91
+
92
+ # 使用 fetchall() 方法获取所有数据
93
+ data = cursor.fetchall()
94
+
95
+ # 处理 bytes 类型的数据
96
+ for row in data:
97
+ for key, value in row.items():
98
+ if isinstance(value, bytes):
99
+ row[key] = value.decode("utf-8") # 转换为字符串
100
+
101
+ # 将数据序列化为 JSON
102
+ json_data = json.dumps(data, ensure_ascii=False)
103
+ print(json_data)
104
+ return json_data
105
+
106
+ # 关闭数据库连接
107
+ db.close()
108
+
109
+ except Exception as e:
110
+ print(f"Error while connecting to MySQL: {e}")', '{"{\" name\" : \" sql\" , \" type\" : \" string\" , \" source\" : \" reference\" , \" is_required\" : true}"}', 'f0dd8f71-e4ee-11ee-8c84-a8a1595801ab', true, 'PUBLIC', 'INTERNAL', '/src/assets/fx/mysql/icon.png', '[{"attrs": {"maxlength": 200, "minlength": 1, "show-word-limit": true}, "field": "host", "label": "host", "required": true, "input_type": "TextInput", "props_info": {"rules": [{"message": "host 为必填属性", "required": true}, {"max": 200, "min": 1, "message": "host长度在 1 到 200 个字符", "trigger": "blur"}]}, "default_value": "x", "show_default_value": false}, {"attrs": {"maxlength": 20, "minlength": 1, "show-word-limit": true}, "field": "port", "label": "port", "required": true, "input_type": "TextInput", "props_info": {"rules": [{"message": "port 为必填属性", "required": true}, {"max": 20, "min": 1, "message": "port长度在 1 到 20 个字符", "trigger": "blur"}]}, "default_value": "3306", "show_default_value": false}, {"attrs": {"maxlength": 200, "minlength": 1, "show-word-limit": true}, "field": "user", "label": "user", "required": true, "input_type": "TextInput", "props_info": {"rules": [{"message": "user 为必填属性", "required": true}, {"max": 200, "min": 1, "message": "user长度在 1 到 200 个字符", "trigger": "blur"}]}, "default_value": "root", "show_default_value": false}, {"attrs": {"type": "password", "maxlength": 200, "minlength": 1, "show-password": true, "show-word-limit": true}, "field": "password", "label": "password", "required": true, "input_type": "PasswordInput", "props_info": {"rules": [{"message": "password 为必填属性", "required": true}, {"max": 200, "min": 1, "message": "password长度在 1 到 200 个字符", "trigger": "blur"}]}, "default_value": "x", "show_default_value": false}, {"attrs": {"maxlength": 200, "minlength": 1, "show-word-limit": true}, "field": "database", "label": "database", "required": true, "input_type": "TextInput", "props_info": {"rules": [{"message": "database 为必填属性", "required": true}, {"max": 200, "min": 1, "message": "database长度在 1 到 200 个字符", "trigger": "blur"}]}, "default_value": "x", "show_default_value": false}]', null, null);
69
111
INSERT INTO function_lib (create_time, update_time, id, name, "desc", code, input_field_list, user_id, is_active, permission_type, function_type, icon, init_field_list, init_params, template_id) VALUES ('2025-03-17 07:37:54.620836 +00:00', '2025-03-17 07:37:54.620887 +00:00', 'bd1e8b88-0302-11f0-87bb-5618c4394482', 'PostgreSQL 查询', '', e'def queryPgSQL(dbname, user, password, host, port, query):
70
112
import psycopg2
71
113
import json
@@ -114,49 +156,7 @@ def default_serializer(obj):
114
156
cursor.close()
115
157
if conn:
116
158
conn.close()
117
- ', '{"{\" name\" : \" dbname\" , \" type\" : \" string\" , \" source\" : \" custom\" , \" is_required\" : true}","{\" name\" : \" user\" , \" type\" : \" string\" , \" source\" : \" custom\" , \" is_required\" : true}","{\" name\" : \" password\" , \" type\" : \" string\" , \" source\" : \" custom\" , \" is_required\" : true}","{\" name\" : \" host\" , \" type\" : \" string\" , \" source\" : \" custom\" , \" is_required\" : true}","{\" name\" : \" port\" , \" type\" : \" string\" , \" source\" : \" custom\" , \" is_required\" : true}","{\" name\" : \" query\" , \" type\" : \" string\" , \" source\" : \" reference\" , \" is_required\" : true}"}', 'f0dd8f71-e4ee-11ee-8c84-a8a1595801ab', true, 'PUBLIC', 'INTERNAL', '/src/assets/fx/postgresql/icon.png', '[]', null, null);
118
- INSERT INTO function_lib (create_time, update_time, id, name, "desc", code, input_field_list, user_id, is_active, permission_type, function_type, icon, init_field_list, init_params, template_id) VALUES ('2025-03-17 08:16:32.626245 +00:00', '2025-03-17 08:16:32.626308 +00:00', '22c21b76-0308-11f0-9694-5618c4394482', 'MySQL 查询', '', e'
119
- def query_mysql(host,port, user, password, database, sql):
120
- import pymysql
121
- import json
122
- from pymysql.cursors import DictCursor
123
-
124
- try:
125
- # 创建连接
126
- db = pymysql.connect(
127
- host=host,
128
- port=int(port),
129
- user=user,
130
- password=password,
131
- database=database,
132
- cursorclass=DictCursor # 使用字典游标
133
- )
134
-
135
- # 使用 cursor() 方法创建一个游标对象 cursor
136
- cursor = db.cursor()
137
-
138
- # 使用 execute() 方法执行 SQL 查询
139
- cursor.execute(sql)
140
-
141
- # 使用 fetchall() 方法获取所有数据
142
- data = cursor.fetchall()
143
-
144
- # 处理 bytes 类型的数据
145
- for row in data:
146
- for key, value in row.items():
147
- if isinstance(value, bytes):
148
- row[key] = value.decode(\" utf-8\" ) # 转换为字符串
149
-
150
- # 将数据序列化为 JSON
151
- json_data = json.dumps(data, ensure_ascii=False)
152
- print(json_data)
153
- return json_data
154
-
155
- # 关闭数据库连接
156
- db.close()
157
-
158
- except Exception as e:
159
- print(f"Error while connecting to MySQL: {e}")', '{"{\" name\" : \" host\" , \" type\" : \" string\" , \" source\" : \" custom\" , \" is_required\" : true}","{\" name\" : \" port\" , \" type\" : \" string\" , \" source\" : \" custom\" , \" is_required\" : true}","{\" name\" : \" user\" , \" type\" : \" string\" , \" source\" : \" custom\" , \" is_required\" : true}","{\" name\" : \" password\" , \" type\" : \" string\" , \" source\" : \" custom\" , \" is_required\" : true}","{\" name\" : \" database\" , \" type\" : \" string\" , \" source\" : \" custom\" , \" is_required\" : true}","{\" name\" : \" sql\" , \" type\" : \" string\" , \" source\" : \" reference\" , \" is_required\" : true}"}', 'f0dd8f71-e4ee-11ee-8c84-a8a1595801ab', true, 'PUBLIC', 'INTERNAL', '/src/assets/fx/mysql/icon.png', '[]', null, null);
159
+ ', '{"{\" name\" : \" query\" , \" type\" : \" string\" , \" source\" : \" reference\" , \" is_required\" : true}"}', 'f0dd8f71-e4ee-11ee-8c84-a8a1595801ab', true, 'PUBLIC', 'INTERNAL', '/src/assets/fx/postgresql/icon.png', '[{"attrs": {"maxlength": 200, "minlength": 1, "show-word-limit": true}, "field": "dbname", "label": "dbname", "required": true, "input_type": "TextInput", "props_info": {"rules": [{"message": "dbname 为必填属性", "required": true}, {"max": 200, "min": 1, "message": "dbname长度在 1 到 200 个字符", "trigger": "blur"}]}, "default_value": "x", "show_default_value": false}, {"attrs": {"maxlength": 200, "minlength": 1, "show-word-limit": true}, "field": "user", "label": "user", "required": true, "input_type": "TextInput", "props_info": {"rules": [{"message": "user 为必填属性", "required": true}, {"max": 200, "min": 1, "message": "user长度在 1 到 200 个字符", "trigger": "blur"}]}, "default_value": "root", "show_default_value": false}, {"attrs": {"type": "password", "maxlength": 200, "minlength": 1, "show-password": true, "show-word-limit": true}, "field": "password", "label": "password", "required": true, "input_type": "PasswordInput", "props_info": {"rules": [{"message": "password 为必填属性", "required": true}, {"max": 200, "min": 1, "message": "password长度在 1 到 200 个字符", "trigger": "blur"}]}, "default_value": "x", "show_default_value": false}, {"attrs": {"maxlength": 200, "minlength": 1, "show-word-limit": true}, "field": "host", "label": "host", "required": true, "input_type": "TextInput", "props_info": {"rules": [{"message": "host 为必填属性", "required": true}, {"max": 200, "min": 1, "message": "host长度在 1 到 200 个字符", "trigger": "blur"}]}, "default_value": "x", "show_default_value": false}, {"attrs": {"maxlength": 20, "minlength": 1, "show-word-limit": true}, "field": "port", "label": "port", "required": true, "input_type": "TextInput", "props_info": {"rules": [{"message": "port 为必填属性", "required": true}, {"max": 20, "min": 1, "message": "port长度在 1 到 20 个字符", "trigger": "blur"}]}, "default_value": "5432", "show_default_value": false}]', null, null);
160
160
161
161
'''
162
162
0 commit comments