From 8d58ec661423cb57b930e5549b2c4cf8c1057d4e Mon Sep 17 00:00:00 2001 From: junjun Date: Fri, 25 Apr 2025 18:49:56 +0800 Subject: [PATCH] feat: datasource api --- backend/apps/api.py | 3 +++ backend/apps/datasource/__init__.py | 0 backend/apps/datasource/api/__init__.py | 0 backend/apps/datasource/api/datasource.py | 9 +++++++++ backend/apps/datasource/crud/__init__.py | 0 backend/apps/datasource/crud/datasource.py | 7 +++++++ backend/apps/datasource/models/__init__.py | 0 backend/apps/datasource/models/datasource.py | 13 +++++++++++++ backend/pyproject.toml | 1 + 9 files changed, 33 insertions(+) create mode 100644 backend/apps/datasource/__init__.py create mode 100644 backend/apps/datasource/api/__init__.py create mode 100644 backend/apps/datasource/api/datasource.py create mode 100644 backend/apps/datasource/crud/__init__.py create mode 100644 backend/apps/datasource/crud/datasource.py create mode 100644 backend/apps/datasource/models/__init__.py create mode 100644 backend/apps/datasource/models/datasource.py diff --git a/backend/apps/api.py b/backend/apps/api.py index d1d32f59..0c0d312b 100644 --- a/backend/apps/api.py +++ b/backend/apps/api.py @@ -2,10 +2,13 @@ from fastapi import APIRouter from apps.system.api import login, user from apps.settings.api import terminology +from apps.datasource.api import datasource + api_router = APIRouter() api_router.include_router(login.router) api_router.include_router(user.router) api_router.include_router(terminology.router) +api_router.include_router(datasource.router) diff --git a/backend/apps/datasource/__init__.py b/backend/apps/datasource/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/backend/apps/datasource/api/__init__.py b/backend/apps/datasource/api/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/backend/apps/datasource/api/datasource.py b/backend/apps/datasource/api/datasource.py new file mode 100644 index 00000000..d7bdd719 --- /dev/null +++ b/backend/apps/datasource/api/datasource.py @@ -0,0 +1,9 @@ +from fastapi import APIRouter, HTTPException +from ..crud.datasource import get_datasource_list +from common.core.deps import SessionDep + +router = APIRouter(tags=["datasource"], prefix="/datasource") + +@router.get("/list") +def datasource_list(session: SessionDep): + return get_datasource_list(session=session) \ No newline at end of file diff --git a/backend/apps/datasource/crud/__init__.py b/backend/apps/datasource/crud/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/backend/apps/datasource/crud/datasource.py b/backend/apps/datasource/crud/datasource.py new file mode 100644 index 00000000..8536bf44 --- /dev/null +++ b/backend/apps/datasource/crud/datasource.py @@ -0,0 +1,7 @@ +from sqlmodel import Session, select +from ..models.datasource import core_datasource + +def get_datasource_list(session: Session) -> core_datasource | None: + statement = select(core_datasource) + datasource_list = session.exec(statement).fetchall() + return datasource_list \ No newline at end of file diff --git a/backend/apps/datasource/models/__init__.py b/backend/apps/datasource/models/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/backend/apps/datasource/models/datasource.py b/backend/apps/datasource/models/datasource.py new file mode 100644 index 00000000..c161a32c --- /dev/null +++ b/backend/apps/datasource/models/datasource.py @@ -0,0 +1,13 @@ +from sqlmodel import SQLModel, Field +from sqlalchemy import Column, Text, BigInteger, DateTime, Integer, Identity +from datetime import datetime + +class core_datasource(SQLModel, table=True): + id: int = Field(sa_column=Column(Integer, Identity(always=True), nullable=False, primary_key=True)) + name: str = Field(max_length=128, nullable=False) + description: str = Field(max_length=512, nullable=True) + type: str = Field(max_length=64) + configuration: str = Field(sa_column=Column(Text)) + create_time: datetime = Field(sa_column=Column(DateTime(timezone=True), nullable=True)) + create_by: int = Field(sa_column=Column(BigInteger())) + status: str = Field(max_length=64, nullable=True) \ No newline at end of file diff --git a/backend/pyproject.toml b/backend/pyproject.toml index a0e01aeb..33a0e8ca 100644 --- a/backend/pyproject.toml +++ b/backend/pyproject.toml @@ -18,6 +18,7 @@ dependencies = [ "pydantic-settings<3.0.0,>=2.2.1", "sentry-sdk[fastapi]<2.0.0,>=1.40.6", "pyjwt<3.0.0,>=2.8.0", + "pyodbc (>=5.2.0,<5.2.1)", ] [[tool.uv.index]] url = "https://pypi.tuna.tsinghua.edu.cn/simple"