mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-08-05 10:29:36 +00:00
DDL run bug fix
This commit is contained in:
parent
0b33943dd9
commit
1547c3aff1
@ -10,3 +10,8 @@ class DBConfig(BaseModel):
|
|||||||
db_user: str = ""
|
db_user: str = ""
|
||||||
db_pwd: str = ""
|
db_pwd: str = ""
|
||||||
comment: str = ""
|
comment: str = ""
|
||||||
|
|
||||||
|
class DbTypeInfo(BaseModel):
|
||||||
|
db_type:str
|
||||||
|
is_file_db: bool = False
|
||||||
|
|
||||||
|
@ -47,6 +47,27 @@ class DuckdbConnectConfig:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("add db connect info error1!" + str(e))
|
print("add db connect info error1!" + str(e))
|
||||||
|
|
||||||
|
def update_db_info(self,
|
||||||
|
db_name,
|
||||||
|
db_type,
|
||||||
|
db_path,
|
||||||
|
db_host: str,
|
||||||
|
db_port: int,
|
||||||
|
db_user: str,
|
||||||
|
db_pwd: str,
|
||||||
|
comment: str ):
|
||||||
|
old_db_conf = self.get_db_config(db_name)
|
||||||
|
if old_db_conf:
|
||||||
|
try:
|
||||||
|
cursor = self.connect.cursor()
|
||||||
|
cursor.execute(f"UPDATE connect_config set db_type={db_type}, db_path={db_path}, db_host={db_host}, db_port={db_port}, db_user={db_user}, db_pwd={db_pwd}, comment={comment} where db_name={db_name}")
|
||||||
|
cursor.commit()
|
||||||
|
self.connect.commit()
|
||||||
|
except Exception as e:
|
||||||
|
print("edit db connect info error2!" + str(e))
|
||||||
|
return True
|
||||||
|
raise ValueError(f"{db_name} not have config info!")
|
||||||
|
|
||||||
def get_file_db_name(self, path):
|
def get_file_db_name(self, path):
|
||||||
try:
|
try:
|
||||||
conn = duckdb.connect(path)
|
conn = duckdb.connect(path)
|
||||||
@ -55,6 +76,7 @@ class DuckdbConnectConfig:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise "Unusable duckdb database path:" + path
|
raise "Unusable duckdb database path:" + path
|
||||||
|
|
||||||
|
|
||||||
def add_file_db(self, db_name, db_type, db_path: str, comment: str = ""):
|
def add_file_db(self, db_name, db_type, db_path: str, comment: str = ""):
|
||||||
try:
|
try:
|
||||||
cursor = self.connect.cursor()
|
cursor = self.connect.cursor()
|
||||||
@ -89,7 +111,7 @@ class DuckdbConnectConfig:
|
|||||||
for i, field in enumerate(fields):
|
for i, field in enumerate(fields):
|
||||||
row_dict[field] = row_1[i]
|
row_dict[field] = row_1[i]
|
||||||
return row_dict
|
return row_dict
|
||||||
return {}
|
return None
|
||||||
|
|
||||||
def get_db_list(self):
|
def get_db_list(self):
|
||||||
if os.path.isfile(duckdb_path):
|
if os.path.isfile(duckdb_path):
|
||||||
|
@ -117,6 +117,16 @@ class ConnectManager:
|
|||||||
def delete_db(self, db_name: str):
|
def delete_db(self, db_name: str):
|
||||||
return self.storage.delete_db(db_name)
|
return self.storage.delete_db(db_name)
|
||||||
|
|
||||||
|
def edit_db(self, db_info: DBConfig):
|
||||||
|
return self.storage.update_db_info(db_info.db_name,
|
||||||
|
db_info.db_type,
|
||||||
|
db_info.file_path,
|
||||||
|
db_info.db_host,
|
||||||
|
db_info.db_port,
|
||||||
|
db_info.db_user,
|
||||||
|
db_info.db_pwd,
|
||||||
|
db_info.comment)
|
||||||
|
|
||||||
def add_db(self, db_info: DBConfig):
|
def add_db(self, db_info: DBConfig):
|
||||||
db_type = DBType.of_db_type(db_info.db_type)
|
db_type = DBType.of_db_type(db_info.db_type)
|
||||||
if db_type.is_file_db():
|
if db_type.is_file_db():
|
||||||
|
@ -25,7 +25,7 @@ from pilot.openapi.api_v1.api_view_model import (
|
|||||||
MessageVo,
|
MessageVo,
|
||||||
ChatSceneVo,
|
ChatSceneVo,
|
||||||
)
|
)
|
||||||
from pilot.connections.db_conn_info import DBConfig
|
from pilot.connections.db_conn_info import DBConfig, DbTypeInfo
|
||||||
from pilot.configs.config import Config
|
from pilot.configs.config import Config
|
||||||
from pilot.server.knowledge.service import KnowledgeService
|
from pilot.server.knowledge.service import KnowledgeService
|
||||||
from pilot.server.knowledge.request.request import KnowledgeSpaceRequest
|
from pilot.server.knowledge.request.request import KnowledgeSpaceRequest
|
||||||
@ -35,7 +35,7 @@ from pilot.scene.base import ChatScene
|
|||||||
from pilot.scene.chat_factory import ChatFactory
|
from pilot.scene.chat_factory import ChatFactory
|
||||||
from pilot.configs.model_config import LOGDIR
|
from pilot.configs.model_config import LOGDIR
|
||||||
from pilot.utils import build_logger
|
from pilot.utils import build_logger
|
||||||
from pilot.scene.base_message import BaseMessage
|
from pilot.common.schema import DBType
|
||||||
from pilot.memory.chat_history.duckdb_history import DuckdbHistoryMemory
|
from pilot.memory.chat_history.duckdb_history import DuckdbHistoryMemory
|
||||||
from pilot.scene.message import OnceConversation
|
from pilot.scene.message import OnceConversation
|
||||||
|
|
||||||
@ -106,14 +106,23 @@ async def dialogue_list(db_config: DBConfig = Body()):
|
|||||||
return Result.succ(CFG.LOCAL_DB_MANAGE.add_db(db_config))
|
return Result.succ(CFG.LOCAL_DB_MANAGE.add_db(db_config))
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/v1/chat/db/edit", response_model=Result[bool])
|
||||||
|
async def dialogue_list(db_config: DBConfig = Body()):
|
||||||
|
return Result.succ(CFG.LOCAL_DB_MANAGE.edit_db(db_config))
|
||||||
|
|
||||||
|
|
||||||
@router.post("/v1/chat/db/delete", response_model=Result[bool])
|
@router.post("/v1/chat/db/delete", response_model=Result[bool])
|
||||||
async def dialogue_list(db_name: str = None):
|
async def dialogue_list(db_name: str = None):
|
||||||
return Result.succ(CFG.LOCAL_DB_MANAGE.delete_db(db_name))
|
return Result.succ(CFG.LOCAL_DB_MANAGE.delete_db(db_name))
|
||||||
|
|
||||||
|
|
||||||
@router.get("/v1/chat/db/support/type", response_model=Result[str])
|
@router.get("/v1/chat/db/support/type", response_model=Result[DbTypeInfo])
|
||||||
async def db_support_types():
|
async def db_support_types():
|
||||||
return Result[str].succ(["mysql", "mssql", "duckdb"])
|
support_types = [DBType.Mysql, DBType.MSSQL, DBType.DuckDb]
|
||||||
|
db_type_infos = []
|
||||||
|
for type in support_types:
|
||||||
|
db_type_infos.append(DbTypeInfo(type.value(), type.is_file_db()))
|
||||||
|
return Result[DbTypeInfo].succ(db_type_infos)
|
||||||
|
|
||||||
|
|
||||||
@router.get("/v1/chat/dialogue/list", response_model=Result[ConversationVo])
|
@router.get("/v1/chat/dialogue/list", response_model=Result[ConversationVo])
|
||||||
@ -160,7 +169,7 @@ async def dialogue_scenes():
|
|||||||
|
|
||||||
@router.post("/v1/chat/dialogue/new", response_model=Result[ConversationVo])
|
@router.post("/v1/chat/dialogue/new", response_model=Result[ConversationVo])
|
||||||
async def dialogue_new(
|
async def dialogue_new(
|
||||||
chat_mode: str = ChatScene.ChatNormal.value(), user_id: str = None
|
chat_mode: str = ChatScene.ChatNormal.value(), user_id: str = None
|
||||||
):
|
):
|
||||||
conv_vo = __new_conversation(chat_mode, user_id)
|
conv_vo = __new_conversation(chat_mode, user_id)
|
||||||
return Result.succ(conv_vo)
|
return Result.succ(conv_vo)
|
||||||
|
0
pilot/scene/chat_data/__init__.py
Normal file
0
pilot/scene/chat_data/__init__.py
Normal file
0
pilot/scene/chat_data/chat_excel/__init__.py
Normal file
0
pilot/scene/chat_data/chat_excel/__init__.py
Normal file
Loading…
Reference in New Issue
Block a user