Skip to content

Commit

Permalink
添加对数据源添加时候的提示
Browse files Browse the repository at this point in the history
  • Loading branch information
iokk3732 committed Apr 25, 2024
1 parent 2276e4a commit 6ba99b7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
5 changes: 5 additions & 0 deletions airda/agent/exception/already_exists_error.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from airda.framework.exception.agent_error import AgentError


class AlreadyExistsError(AgentError):
CODE = 10002
3 changes: 2 additions & 1 deletion airda/agent/storage/repositories/datasource_repository.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import List

from airda.agent import log
from airda.agent.exception.already_exists_error import AlreadyExistsError
from airda.agent.storage.entity.datasource import Datasource
from airda.agent.storage.repositories.respository import Repository

Expand All @@ -13,7 +14,7 @@ class DatasourceRepository(Repository):
def add(self, datasource: Datasource) -> Datasource:
has = self.find_one(datasource.name)
if has:
raise Exception("datasource already exists")
raise AlreadyExistsError()
datasource_dict = datasource.dict(exclude={"id"})
datasource.id = str(self.storage.insert_one(DB_COLLECTION, datasource_dict))
return datasource
Expand Down
25 changes: 15 additions & 10 deletions airda/cli/startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from airda.agent import DataAgentKey
from airda.agent.agent import DataAgent
from airda.agent.env import DataAgentEnv
from airda.agent.exception.already_exists_error import AlreadyExistsError
from airda.agent.planner.data_agent_planner_params import DataAgentPlannerParams
from airda.agent.storage import StorageKey
from airda.agent.storage.entity.datasource import Datasource, Kind
Expand Down Expand Up @@ -174,17 +175,21 @@ def add(name: str, host: str, port: int, database: str, kind: str, username: str
datasource_repository = context.get_repository(StorageKey.DATASOURCE).convert(
DatasourceRepository
)
datasource_repository.add(
Datasource(
name=name,
host=host,
port=port,
database=database,
kind=kind,
username=username,
password=password,
try:
datasource_repository.add(
Datasource(
name=name,
host=host,
port=port,
database=database,
kind=kind,
username=username,
password=password,
)
)
)
output_colored_text("执行成功", "success")
except AlreadyExistsError:
output_colored_text(f"执行失败, [{name}]数据源已存在", "error")


@datasource.command(help="同步数据源的表字段信息并进行向量化")
Expand Down
2 changes: 1 addition & 1 deletion airda/framework/exception/agent_error.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class AgentError(Exception):
CODE = -1

def __init__(self, msg: str | None):
def __init__(self, msg: str = None):
super().__init__(msg)

0 comments on commit 6ba99b7

Please sign in to comment.