Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

solidui datasouerce #253

Merged
merged 1 commit into from
Dec 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,11 @@
<a target="_blank" href="https://github.com/CloudOrc/SolidUI/blob/main/LICENSE">
<img src="https://img.shields.io/badge/License-Apache%202.0-blue.svg?label=license" />
</a>
<a target="_blank" href="https://www.oracle.com/technetwork/java/javase/downloads/index.html">
<img src="https://img.shields.io/badge/JDK-8-blue.svg" />
</a>


<a target="_blank" href='https://github.com/CloudOrc/SolidUI/fork'>
<img src="https://img.shields.io/github/forks/CloudOrc/SolidUI.svg" alt="github forks"/>
</a>
<a href="">
<img src="https://img.shields.io/github/stars/CloudOrc/SolidUI.svg" alt="github stars"/>
</a>

<a target="_blank" href='https://github.com/CloudOrc/SolidUI/graphs/contributors'>
<img src="https://img.shields.io/github/contributors/CloudOrc/SolidUI.svg?colorB=blue" alt="github contributors"/>
</a>
Expand Down
7 changes: 2 additions & 5 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
<a target="_blank" href="https://github.com/CloudOrc/SolidUI/blob/main/LICENSE">
<img src="https://img.shields.io/badge/License-Apache%202.0-blue.svg?label=license" />
</a>
<a target="_blank" href="https://www.oracle.com/technetwork/java/javase/downloads/index.html">
<img src="https://img.shields.io/badge/JDK-8-blue.svg" />
</a>

<a target="_blank" href='https://github.com/CloudOrc/SolidUI/fork'>
<img src="https://img.shields.io/github/forks/CloudOrc/SolidUI.svg" alt="github forks"/>
Expand Down Expand Up @@ -61,8 +58,8 @@ AI生成图形模型
* 支持多种数据源
* 支持Huggingface space
* 支持插件机器人
* 支持SolidUI-Model
* 支持Large Language Model
* 支持SolidUI模型
* 支持大模型接入
* 容器化部署

# 快速开始
Expand Down
7 changes: 6 additions & 1 deletion solidui/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,9 @@
# Console Log Settings

LOG_FORMAT = "%(asctime)s:%(levelname)s:%(name)s:%(message)s"
LOG_LEVEL = "DEBUG"
LOG_LEVEL = "DEBUG"

PREFERRED_DATABASES: list[str] = [
"MySQL",
"SQLite",
]
91 changes: 90 additions & 1 deletion solidui/daos/datasource.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,98 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Any
import logging

from solidui.utils.page_info import PageInfo

from solidui.daos.base import BaseDAO
from solidui.daos.exceptions import DAOCreateFailedError, DAOUpdateFailedError, DAONotFound, DAODeleteFailedError
from solidui.entity.core import DataSource

logger = logging.getLogger(__name__)


class DatasourceDAO(BaseDAO[DataSource]):
class DataSourceDAO(BaseDAO[DataSource]):
model_cls = DataSource

@classmethod
def create_data_source(cls, data_source: DataSource) -> DataSource:
new_data_source = super().find_one_or_none(datasource_name=data_source.datasource_name)
if new_data_source is not None:
raise DAOCreateFailedError(message="DataSource is already exists")

return super().create(item=data_source)

@classmethod
def get_data_source_name(cls, data_source_name: int) -> DataSource:
return super().find_one_or_none(datasource_name=data_source_name)

@classmethod
def get_data_source_id(cls, data_source_id: int) -> DataSource:
return super().find_by_id(data_source_id)

@classmethod
def exist_data_source(cls, data_source_id: int) -> DataSource:
data_source = super().find_by_id(data_source_id)
if data_source is None:
raise DAONotFound(message="DataSource is null")

try:
return super().update(item=data_source, attributes={'expire': True})
except DAOUpdateFailedError as ex:
logger.exception(ex.exception)
raise ex

@classmethod
def get_data_source_page(cls, page_no: int, page_size: int, name_filter: str = None, type_filter: int = None,
expire_filter: bool = None) -> PageInfo:
query = cls.model_cls.query

# Apply filters
if name_filter is not None:
query = query.filter(cls.model_cls.datasource_name.like(f"%{name_filter}%"))
if type_filter is not None:
query = query.filter(cls.model_cls.datasource_type_id == type_filter)
if expire_filter is not None:
query = query.filter(cls.model_cls.expire == expire_filter)

# Apply pagination
pagination = query.paginate(page_no, page_size, error_out=False)

page_info = PageInfo(page_no, page_size)
page_info.set_total(pagination.total)
page_info.set_total_list(pagination.items)

return page_info

@classmethod
def delete_data_source(cls, data_source_id: int) -> None:
if data_source_id is None:
raise DAONotFound(message="DataSource id is required")

data_source = cls.find_by_id(data_source_id)
if not data_source:
raise DAONotFound(message="DataSource is required")

try:
super().delete(data_source)
except DAODeleteFailedError as ex:
logger.exception(ex.exception)
raise ex

@classmethod
def update_data_source(cls, data_source: DataSource) -> DataSource:
if data_source.id is None:
raise DAONotFound(message="DataSource id is required")

existing_data_source = cls.find_by_id(data_source.id)
if not existing_data_source:
raise DAONotFound(message="DataSource is required")

try:
return super().update(existing_data_source, data_source.__dict__)
except DAOUpdateFailedError as ex:
logger.exception(ex)
raise ex

21 changes: 20 additions & 1 deletion solidui/daos/datasource_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,23 @@
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# limitations under the License.

from solidui.daos.base import BaseDAO
from solidui.daos.exceptions import DAONotFound
from solidui.entity.core import DataSourceType


class DataSourceTypeDAO(BaseDAO[DataSourceType]):
model_cls = DataSourceType

@classmethod
def all_list(cls) -> DataSourceType:
return super().find_all()

@classmethod
def get_id(cls, id: int) -> DataSourceType:
data_source_type = super().find_by_id(id)
if not data_source_type:
raise DAONotFound(message="DataSourceType not found")
return data_source_type
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,4 @@
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from abc import ABC, abstractmethod

class Plugin(ABC):

@abstractmethod
def get_name(self):
pass

# limitations under the License.
55 changes: 0 additions & 55 deletions solidui/datasource_plugin/base_jdbc_client.py

This file was deleted.

37 changes: 0 additions & 37 deletions solidui/datasource_plugin/base_jdbc_client_factory.py

This file was deleted.

23 changes: 0 additions & 23 deletions solidui/datasource_plugin/connect_dto.py

This file was deleted.

21 changes: 0 additions & 21 deletions solidui/datasource_plugin/connection_factory.py

This file was deleted.

24 changes: 0 additions & 24 deletions solidui/datasource_plugin/constants.py

This file was deleted.

Loading
Loading