mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-09-12 12:37:14 +00:00
refactor: Refactor storage and new serve template (#947)
This commit is contained in:
@@ -7,10 +7,6 @@ from dbgpt.storage.metadata import BaseDao, Model
|
||||
|
||||
class MyPluginEntity(Model):
|
||||
__tablename__ = "my_plugin"
|
||||
__table_args__ = {
|
||||
"mysql_charset": "utf8mb4",
|
||||
"mysql_collate": "utf8mb4_unicode_ci",
|
||||
}
|
||||
id = Column(Integer, primary_key=True, comment="autoincrement id")
|
||||
tenant = Column(String(255), nullable=True, comment="user's tenant")
|
||||
user_code = Column(String(255), nullable=False, comment="user code")
|
||||
@@ -32,7 +28,7 @@ class MyPluginEntity(Model):
|
||||
UniqueConstraint("user_code", "name", name="uk_name")
|
||||
|
||||
|
||||
class MyPluginDao(BaseDao[MyPluginEntity]):
|
||||
class MyPluginDao(BaseDao):
|
||||
def add(self, engity: MyPluginEntity):
|
||||
session = self.get_raw_session()
|
||||
my_plugin = MyPluginEntity(
|
||||
@@ -53,7 +49,7 @@ class MyPluginDao(BaseDao[MyPluginEntity]):
|
||||
session.close()
|
||||
return id
|
||||
|
||||
def update(self, entity: MyPluginEntity):
|
||||
def raw_update(self, entity: MyPluginEntity):
|
||||
session = self.get_raw_session()
|
||||
updated = session.merge(entity)
|
||||
session.commit()
|
||||
@@ -128,7 +124,7 @@ class MyPluginDao(BaseDao[MyPluginEntity]):
|
||||
session.close()
|
||||
return count
|
||||
|
||||
def delete(self, plugin_id: int):
|
||||
def raw_delete(self, plugin_id: int):
|
||||
session = self.get_raw_session()
|
||||
if plugin_id is None:
|
||||
raise Exception("plugin_id is None")
|
||||
|
@@ -11,10 +11,6 @@ char_set_sql = DDL("ALTER TABLE plugin_hub CONVERT TO CHARACTER SET utf8mb4")
|
||||
|
||||
class PluginHubEntity(Model):
|
||||
__tablename__ = "plugin_hub"
|
||||
__table_args__ = {
|
||||
"mysql_charset": "utf8mb4",
|
||||
"mysql_collate": "utf8mb4_unicode_ci",
|
||||
}
|
||||
id = Column(
|
||||
Integer, primary_key=True, autoincrement=True, comment="autoincrement id"
|
||||
)
|
||||
@@ -36,7 +32,7 @@ class PluginHubEntity(Model):
|
||||
Index("idx_q_type", "type")
|
||||
|
||||
|
||||
class PluginHubDao(BaseDao[PluginHubEntity]):
|
||||
class PluginHubDao(BaseDao):
|
||||
def add(self, engity: PluginHubEntity):
|
||||
session = self.get_raw_session()
|
||||
timezone = pytz.timezone("Asia/Shanghai")
|
||||
@@ -56,7 +52,7 @@ class PluginHubDao(BaseDao[PluginHubEntity]):
|
||||
session.close()
|
||||
return id
|
||||
|
||||
def update(self, entity: PluginHubEntity):
|
||||
def raw_update(self, entity: PluginHubEntity):
|
||||
session = self.get_raw_session()
|
||||
try:
|
||||
updated = session.merge(entity)
|
||||
@@ -131,7 +127,7 @@ class PluginHubDao(BaseDao[PluginHubEntity]):
|
||||
session.close()
|
||||
return count
|
||||
|
||||
def delete(self, plugin_id: int):
|
||||
def raw_delete(self, plugin_id: int):
|
||||
session = self.get_raw_session()
|
||||
if plugin_id is None:
|
||||
raise Exception("plugin_id is None")
|
||||
|
@@ -159,7 +159,7 @@ class AgentHub:
|
||||
plugin_hub_info.name = git_plugin._name
|
||||
plugin_hub_info.version = git_plugin._version
|
||||
plugin_hub_info.description = git_plugin._description
|
||||
self.hub_dao.update(plugin_hub_info)
|
||||
self.hub_dao.raw_update(plugin_hub_info)
|
||||
except Exception as e:
|
||||
raise ValueError(f"Update Agent Hub Db Info Faild!{str(e)}")
|
||||
|
||||
@@ -194,7 +194,7 @@ class AgentHub:
|
||||
my_plugin_entiy.user_name = user
|
||||
my_plugin_entiy.tenant = ""
|
||||
my_plugin_entiy.file_name = doc_file.filename
|
||||
self.my_plugin_dao.update(my_plugin_entiy)
|
||||
self.my_plugin_dao.raw_update(my_plugin_entiy)
|
||||
|
||||
def reload_my_plugins(self):
|
||||
logger.info(f"load_plugins start!")
|
||||
|
Reference in New Issue
Block a user