mirror of
https://gh-proxy.org/https://github.com/klinsmaya/SQLBot.git
synced 2026-11-09 01:36:57 +08:00
feat: choose tables, save table and field
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
from fastapi import APIRouter
|
||||
from ..crud.datasource import get_datasource_list, check_status, create_ds, update_ds, delete_ds, getTables, getFields, \
|
||||
execSql, update_table_and_fields, getTablesByDs
|
||||
execSql, update_table_and_fields, getTablesByDs, chooseTables
|
||||
from common.core.deps import SessionDep
|
||||
from ..models.datasource import CoreDatasource, CreateDatasource, EditObj
|
||||
from ..models.datasource import CoreDatasource, CreateDatasource, EditObj, CoreTable
|
||||
from ..crud.table import get_tables_by_ds_id
|
||||
from ..crud.field import get_fields_by_table_id
|
||||
from typing import List
|
||||
|
||||
router = APIRouter(tags=["datasource"], prefix="/datasource")
|
||||
|
||||
@@ -24,6 +25,11 @@ async def add(session: SessionDep, ds: CreateDatasource):
|
||||
return create_ds(session, ds)
|
||||
|
||||
|
||||
@router.post("/chooseTables/{id}")
|
||||
async def choose_tables(session: SessionDep, id: int, tables: List[CoreTable]):
|
||||
chooseTables(session, id, tables)
|
||||
|
||||
|
||||
@router.post("/update", response_model=CoreDatasource)
|
||||
async def update(session: SessionDep, ds: CoreDatasource):
|
||||
return update_ds(session, ds)
|
||||
@@ -54,12 +60,12 @@ async def exec_sql(session: SessionDep, id: int, sql: str):
|
||||
return execSql(session, id, sql)
|
||||
|
||||
|
||||
@router.get("/tableList/{id}")
|
||||
@router.post("/tableList/{id}")
|
||||
async def table_list(session: SessionDep, id: int):
|
||||
return get_tables_by_ds_id(session, id)
|
||||
|
||||
|
||||
@router.get("/fieldList/{id}")
|
||||
@router.post("/fieldList/{id}")
|
||||
async def field_list(session: SessionDep, id: int):
|
||||
return get_fields_by_table_id(session, id)
|
||||
|
||||
|
||||
@@ -50,6 +50,11 @@ def create_ds(session: SessionDep, create_ds: CreateDatasource):
|
||||
return ds
|
||||
|
||||
|
||||
def chooseTables(session: SessionDep, id: int, tables: List[CoreTable]):
|
||||
ds = session.query(CoreDatasource).filter(CoreDatasource.id == id).first()
|
||||
sync_table(session, ds, tables)
|
||||
|
||||
|
||||
def update_ds(session: SessionDep, ds: CoreDatasource):
|
||||
ds.id = int(ds.id)
|
||||
status = check_status(session, ds)
|
||||
|
||||
Reference in New Issue
Block a user