DDL run bug fix

This commit is contained in:
yhjun1026 2023-07-27 17:57:18 +08:00
parent 0b33943dd9
commit 1547c3aff1
8 changed files with 52 additions and 6 deletions

View File

@ -10,3 +10,8 @@ class DBConfig(BaseModel):
db_user: str = ""
db_pwd: str = ""
comment: str = ""
class DbTypeInfo(BaseModel):
db_type:str
is_file_db: bool = False

View File

@ -47,6 +47,27 @@ class DuckdbConnectConfig:
except Exception as 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):
try:
conn = duckdb.connect(path)
@ -55,6 +76,7 @@ class DuckdbConnectConfig:
except Exception as e:
raise "Unusable duckdb database path:" + path
def add_file_db(self, db_name, db_type, db_path: str, comment: str = ""):
try:
cursor = self.connect.cursor()
@ -89,7 +111,7 @@ class DuckdbConnectConfig:
for i, field in enumerate(fields):
row_dict[field] = row_1[i]
return row_dict
return {}
return None
def get_db_list(self):
if os.path.isfile(duckdb_path):

View File

@ -117,6 +117,16 @@ class ConnectManager:
def delete_db(self, db_name: str):
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):
db_type = DBType.of_db_type(db_info.db_type)
if db_type.is_file_db():

View File

@ -25,7 +25,7 @@ from pilot.openapi.api_v1.api_view_model import (
MessageVo,
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.server.knowledge.service import KnowledgeService
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.configs.model_config import LOGDIR
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.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))
@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])
async def dialogue_list(db_name: str = None):
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():
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])
@ -160,7 +169,7 @@ async def dialogue_scenes():
@router.post("/v1/chat/dialogue/new", response_model=Result[ConversationVo])
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)
return Result.succ(conv_vo)

View File