Skip to content

Commit

Permalink
support function trigger view
Browse files Browse the repository at this point in the history
  • Loading branch information
Chat2DB-Pro committed Jul 16, 2023
1 parent d9d78af commit 288b8cc
Show file tree
Hide file tree
Showing 18 changed files with 637 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package ai.chat2db.server.domain.api.service;

import ai.chat2db.server.tools.base.wrapper.result.ListResult;
import ai.chat2db.spi.model.Function;
import jakarta.validation.constraints.NotEmpty;

/**
* author jipengfei
* date 2021/9/23 15:22
*/
public interface FunctionService {

/**
* Querying all functions under a schema.
*
* @param databaseName
* @return
*/
ListResult<Function> functions(@NotEmpty String databaseName, String schemaName);


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package ai.chat2db.server.domain.api.service;

import ai.chat2db.server.tools.base.wrapper.result.ListResult;
import ai.chat2db.spi.model.Procedure;
import jakarta.validation.constraints.NotEmpty;

public interface ProcedureService {

/**
* Querying all procedures under a schema.
*
* @param databaseName
* @return
*/
ListResult<Procedure> procedures(@NotEmpty String databaseName, String schemaName);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package ai.chat2db.server.domain.api.service;

import ai.chat2db.server.tools.base.wrapper.result.ListResult;
import ai.chat2db.spi.model.Trigger;
import jakarta.validation.constraints.NotEmpty;

public interface TriggerService {

/**
* Querying all triggers under a schema.
*
* @param databaseName
* @return
*/
ListResult<Trigger> triggers(@NotEmpty String databaseName, String schemaName);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package ai.chat2db.server.domain.api.service;

import ai.chat2db.server.tools.base.wrapper.result.ListResult;
import ai.chat2db.spi.model.Table;
import jakarta.validation.constraints.NotEmpty;

/**
* author jipengfei
* date 2021/9/23 15:22
*/
public interface ViewService {

/**
* Querying all views under a schema.
*
* @param databaseName
* @return
*/
ListResult<Table> views(@NotEmpty String databaseName, String schemaName);


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package ai.chat2db.server.domain.core.impl;

import ai.chat2db.server.domain.api.service.FunctionService;
import ai.chat2db.server.tools.base.wrapper.result.ListResult;
import ai.chat2db.spi.model.Function;
import ai.chat2db.spi.sql.Chat2DBContext;
import org.springframework.stereotype.Service;

@Service
public class FunctionServiceImpl implements FunctionService {
@Override
public ListResult<Function> functions(String databaseName, String schemaName) {
return ListResult.of(Chat2DBContext.getMetaData().functions(databaseName, schemaName));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package ai.chat2db.server.domain.core.impl;

import ai.chat2db.server.domain.api.service.ProcedureService;
import ai.chat2db.server.tools.base.wrapper.result.ListResult;
import ai.chat2db.spi.model.Procedure;
import ai.chat2db.spi.sql.Chat2DBContext;
import org.springframework.stereotype.Service;

@Service
public class ProcedureServiceImpl implements ProcedureService {

@Override
public ListResult<Procedure> procedures(String databaseName, String schemaName) {
return ListResult.of(Chat2DBContext.getMetaData().procedures(databaseName, schemaName));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package ai.chat2db.server.domain.core.impl;

import ai.chat2db.server.domain.api.service.TriggerService;
import ai.chat2db.server.tools.base.wrapper.result.ListResult;
import ai.chat2db.spi.model.Trigger;
import ai.chat2db.spi.sql.Chat2DBContext;
import org.springframework.stereotype.Service;

@Service
public class TriggerServiceImpl implements TriggerService {
@Override
public ListResult<Trigger> triggers(String databaseName, String schemaName) {
return ListResult.of(Chat2DBContext.getMetaData().triggers(databaseName, schemaName));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package ai.chat2db.server.domain.core.impl;

import ai.chat2db.server.domain.api.service.ViewService;
import ai.chat2db.server.tools.base.wrapper.result.ListResult;
import ai.chat2db.spi.model.Table;
import ai.chat2db.spi.sql.Chat2DBContext;
import org.springframework.stereotype.Service;

@Service
public class ViewServiceImpl implements ViewService {

@Override
public ListResult<Table> views(String databaseName, String schemaName) {
return ListResult.of(Chat2DBContext.getMetaData().views(databaseName, schemaName));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package ai.chat2db.server.web.api.controller.rdb;

import ai.chat2db.server.domain.api.param.DatabaseOperationParam;
import ai.chat2db.server.domain.api.param.MetaDataQueryParam;
import ai.chat2db.server.domain.api.service.DatabaseService;
import ai.chat2db.server.domain.api.service.DlTemplateService;
import ai.chat2db.server.domain.api.service.TableService;
import ai.chat2db.server.tools.base.wrapper.result.ActionResult;
import ai.chat2db.server.tools.base.wrapper.result.DataResult;
import ai.chat2db.server.web.api.aspect.ConnectionInfoAspect;
import ai.chat2db.server.web.api.controller.data.source.request.DataSourceBaseRequest;
import ai.chat2db.server.web.api.controller.rdb.converter.RdbWebConverter;
import ai.chat2db.server.web.api.controller.rdb.request.UpdateDatabaseRequest;
import ai.chat2db.server.web.api.controller.rdb.vo.MetaSchemaVO;
import ai.chat2db.spi.model.MetaSchema;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@ConnectionInfoAspect
@RequestMapping("/api/rdb/datbase")
@RestController
public class DatabaseController {

@Autowired
private TableService tableService;

@Autowired
private DlTemplateService dlTemplateService;

@Autowired
private RdbWebConverter rdbWebConverter;

@Autowired
private DatabaseService databaseService;
/**
* 查询数据库里包含的database_schema_list
*
* @param request
* @return
*/
@GetMapping("/database_schema_list")
public DataResult<MetaSchemaVO> databaseSchemaList(@Valid DataSourceBaseRequest request) {
MetaDataQueryParam queryParam = MetaDataQueryParam.builder().dataSourceId(request.getDataSourceId()).refresh(
request.isRefresh()).build();
DataResult<MetaSchema> result = databaseService.queryDatabaseSchema(queryParam);
MetaSchemaVO schemaDto2vo = rdbWebConverter.metaSchemaDto2vo(result.getData());
return DataResult.of(schemaDto2vo);
}


/**
* 删除数据库
*
* @param request
* @return
*/
@PostMapping("/delete_database")
public ActionResult deleteDatabase(@Valid @RequestBody DataSourceBaseRequest request) {
DatabaseOperationParam param = DatabaseOperationParam.builder().databaseName(request.getDatabaseName()).build();
return databaseService.deleteDatabase(param);
}

/**
* 创建database
*
* @param request
* @return
*/
@PostMapping("/create_database")
public ActionResult createDatabase(@Valid @RequestBody DataSourceBaseRequest request) {
DatabaseOperationParam param = DatabaseOperationParam.builder().databaseName(request.getDatabaseName()).build();
return databaseService.createDatabase(param);
}


/**
* 修改database
*
* @param request
* @return
*/
@PostMapping("/modify_database")
public ActionResult modifyDatabase(@Valid @RequestBody UpdateDatabaseRequest request) {
DatabaseOperationParam param = DatabaseOperationParam.builder().databaseName(request.getDatabaseName())
.newDatabaseName(request.getNewDatabaseName()).build();
return databaseService.modifyDatabase(param);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package ai.chat2db.server.web.api.controller.rdb;

import ai.chat2db.server.domain.api.service.FunctionService;
import ai.chat2db.server.tools.base.wrapper.result.ListResult;
import ai.chat2db.server.web.api.aspect.ConnectionInfoAspect;
import ai.chat2db.server.web.api.controller.rdb.request.TableBriefQueryRequest;
import ai.chat2db.spi.model.Function;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@ConnectionInfoAspect
@RequestMapping("/api/rdb/function")
@RestController
public class FunctionController {

@Autowired
private FunctionService functionService;


@GetMapping("/list")
public ListResult<Function> list(@Valid TableBriefQueryRequest request) {
return functionService.functions(request.getDatabaseName(), request.getSchemaName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package ai.chat2db.server.web.api.controller.rdb;

import ai.chat2db.server.domain.api.service.ProcedureService;
import ai.chat2db.server.tools.base.wrapper.result.ListResult;
import ai.chat2db.server.web.api.aspect.ConnectionInfoAspect;
import ai.chat2db.server.web.api.controller.rdb.request.TableBriefQueryRequest;
import ai.chat2db.spi.model.Procedure;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@ConnectionInfoAspect
@RequestMapping("/api/rdb/procedure")
@RestController
public class ProcedureController {

private ProcedureService procedureService;

@GetMapping("/list")
public ListResult<Procedure> list(@Valid TableBriefQueryRequest request) {
return procedureService.procedures(request.getDatabaseName(), request.getSchemaName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
@ConnectionInfoAspect
@RequestMapping("/api/rdb/ddl")
@RestController
@Deprecated
public class RdbDdlController {

@Autowired
Expand Down Expand Up @@ -183,6 +184,8 @@ public ActionResult modifySchema(@Valid @RequestBody UpdateSchemaRequest request
return databaseService.modifySchema(param);
}



/**
* 查询当前DB下的表columns
* d
Expand Down
Loading

0 comments on commit 288b8cc

Please sign in to comment.