Skip to content

Commit 288b8cc

Browse files
committed
support function trigger view
1 parent d9d78af commit 288b8cc

File tree

18 files changed

+637
-2
lines changed

18 files changed

+637
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package ai.chat2db.server.domain.api.service;
2+
3+
import ai.chat2db.server.tools.base.wrapper.result.ListResult;
4+
import ai.chat2db.spi.model.Function;
5+
import jakarta.validation.constraints.NotEmpty;
6+
7+
/**
8+
* author jipengfei
9+
* date 2021/9/23 15:22
10+
*/
11+
public interface FunctionService {
12+
13+
/**
14+
* Querying all functions under a schema.
15+
*
16+
* @param databaseName
17+
* @return
18+
*/
19+
ListResult<Function> functions(@NotEmpty String databaseName, String schemaName);
20+
21+
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package ai.chat2db.server.domain.api.service;
2+
3+
import ai.chat2db.server.tools.base.wrapper.result.ListResult;
4+
import ai.chat2db.spi.model.Procedure;
5+
import jakarta.validation.constraints.NotEmpty;
6+
7+
public interface ProcedureService {
8+
9+
/**
10+
* Querying all procedures under a schema.
11+
*
12+
* @param databaseName
13+
* @return
14+
*/
15+
ListResult<Procedure> procedures(@NotEmpty String databaseName, String schemaName);
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package ai.chat2db.server.domain.api.service;
2+
3+
import ai.chat2db.server.tools.base.wrapper.result.ListResult;
4+
import ai.chat2db.spi.model.Trigger;
5+
import jakarta.validation.constraints.NotEmpty;
6+
7+
public interface TriggerService {
8+
9+
/**
10+
* Querying all triggers under a schema.
11+
*
12+
* @param databaseName
13+
* @return
14+
*/
15+
ListResult<Trigger> triggers(@NotEmpty String databaseName, String schemaName);
16+
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package ai.chat2db.server.domain.api.service;
2+
3+
import ai.chat2db.server.tools.base.wrapper.result.ListResult;
4+
import ai.chat2db.spi.model.Table;
5+
import jakarta.validation.constraints.NotEmpty;
6+
7+
/**
8+
* author jipengfei
9+
* date 2021/9/23 15:22
10+
*/
11+
public interface ViewService {
12+
13+
/**
14+
* Querying all views under a schema.
15+
*
16+
* @param databaseName
17+
* @return
18+
*/
19+
ListResult<Table> views(@NotEmpty String databaseName, String schemaName);
20+
21+
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package ai.chat2db.server.domain.core.impl;
2+
3+
import ai.chat2db.server.domain.api.service.FunctionService;
4+
import ai.chat2db.server.tools.base.wrapper.result.ListResult;
5+
import ai.chat2db.spi.model.Function;
6+
import ai.chat2db.spi.sql.Chat2DBContext;
7+
import org.springframework.stereotype.Service;
8+
9+
@Service
10+
public class FunctionServiceImpl implements FunctionService {
11+
@Override
12+
public ListResult<Function> functions(String databaseName, String schemaName) {
13+
return ListResult.of(Chat2DBContext.getMetaData().functions(databaseName, schemaName));
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package ai.chat2db.server.domain.core.impl;
2+
3+
import ai.chat2db.server.domain.api.service.ProcedureService;
4+
import ai.chat2db.server.tools.base.wrapper.result.ListResult;
5+
import ai.chat2db.spi.model.Procedure;
6+
import ai.chat2db.spi.sql.Chat2DBContext;
7+
import org.springframework.stereotype.Service;
8+
9+
@Service
10+
public class ProcedureServiceImpl implements ProcedureService {
11+
12+
@Override
13+
public ListResult<Procedure> procedures(String databaseName, String schemaName) {
14+
return ListResult.of(Chat2DBContext.getMetaData().procedures(databaseName, schemaName));
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package ai.chat2db.server.domain.core.impl;
2+
3+
import ai.chat2db.server.domain.api.service.TriggerService;
4+
import ai.chat2db.server.tools.base.wrapper.result.ListResult;
5+
import ai.chat2db.spi.model.Trigger;
6+
import ai.chat2db.spi.sql.Chat2DBContext;
7+
import org.springframework.stereotype.Service;
8+
9+
@Service
10+
public class TriggerServiceImpl implements TriggerService {
11+
@Override
12+
public ListResult<Trigger> triggers(String databaseName, String schemaName) {
13+
return ListResult.of(Chat2DBContext.getMetaData().triggers(databaseName, schemaName));
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package ai.chat2db.server.domain.core.impl;
2+
3+
import ai.chat2db.server.domain.api.service.ViewService;
4+
import ai.chat2db.server.tools.base.wrapper.result.ListResult;
5+
import ai.chat2db.spi.model.Table;
6+
import ai.chat2db.spi.sql.Chat2DBContext;
7+
import org.springframework.stereotype.Service;
8+
9+
@Service
10+
public class ViewServiceImpl implements ViewService {
11+
12+
@Override
13+
public ListResult<Table> views(String databaseName, String schemaName) {
14+
return ListResult.of(Chat2DBContext.getMetaData().views(databaseName, schemaName));
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
package ai.chat2db.server.web.api.controller.rdb;
2+
3+
import ai.chat2db.server.domain.api.param.DatabaseOperationParam;
4+
import ai.chat2db.server.domain.api.param.MetaDataQueryParam;
5+
import ai.chat2db.server.domain.api.service.DatabaseService;
6+
import ai.chat2db.server.domain.api.service.DlTemplateService;
7+
import ai.chat2db.server.domain.api.service.TableService;
8+
import ai.chat2db.server.tools.base.wrapper.result.ActionResult;
9+
import ai.chat2db.server.tools.base.wrapper.result.DataResult;
10+
import ai.chat2db.server.web.api.aspect.ConnectionInfoAspect;
11+
import ai.chat2db.server.web.api.controller.data.source.request.DataSourceBaseRequest;
12+
import ai.chat2db.server.web.api.controller.rdb.converter.RdbWebConverter;
13+
import ai.chat2db.server.web.api.controller.rdb.request.UpdateDatabaseRequest;
14+
import ai.chat2db.server.web.api.controller.rdb.vo.MetaSchemaVO;
15+
import ai.chat2db.spi.model.MetaSchema;
16+
import jakarta.validation.Valid;
17+
import org.springframework.beans.factory.annotation.Autowired;
18+
import org.springframework.web.bind.annotation.GetMapping;
19+
import org.springframework.web.bind.annotation.PostMapping;
20+
import org.springframework.web.bind.annotation.RequestBody;
21+
import org.springframework.web.bind.annotation.RequestMapping;
22+
import org.springframework.web.bind.annotation.RestController;
23+
24+
@ConnectionInfoAspect
25+
@RequestMapping("/api/rdb/datbase")
26+
@RestController
27+
public class DatabaseController {
28+
29+
@Autowired
30+
private TableService tableService;
31+
32+
@Autowired
33+
private DlTemplateService dlTemplateService;
34+
35+
@Autowired
36+
private RdbWebConverter rdbWebConverter;
37+
38+
@Autowired
39+
private DatabaseService databaseService;
40+
/**
41+
* 查询数据库里包含的database_schema_list
42+
*
43+
* @param request
44+
* @return
45+
*/
46+
@GetMapping("/database_schema_list")
47+
public DataResult<MetaSchemaVO> databaseSchemaList(@Valid DataSourceBaseRequest request) {
48+
MetaDataQueryParam queryParam = MetaDataQueryParam.builder().dataSourceId(request.getDataSourceId()).refresh(
49+
request.isRefresh()).build();
50+
DataResult<MetaSchema> result = databaseService.queryDatabaseSchema(queryParam);
51+
MetaSchemaVO schemaDto2vo = rdbWebConverter.metaSchemaDto2vo(result.getData());
52+
return DataResult.of(schemaDto2vo);
53+
}
54+
55+
56+
/**
57+
* 删除数据库
58+
*
59+
* @param request
60+
* @return
61+
*/
62+
@PostMapping("/delete_database")
63+
public ActionResult deleteDatabase(@Valid @RequestBody DataSourceBaseRequest request) {
64+
DatabaseOperationParam param = DatabaseOperationParam.builder().databaseName(request.getDatabaseName()).build();
65+
return databaseService.deleteDatabase(param);
66+
}
67+
68+
/**
69+
* 创建database
70+
*
71+
* @param request
72+
* @return
73+
*/
74+
@PostMapping("/create_database")
75+
public ActionResult createDatabase(@Valid @RequestBody DataSourceBaseRequest request) {
76+
DatabaseOperationParam param = DatabaseOperationParam.builder().databaseName(request.getDatabaseName()).build();
77+
return databaseService.createDatabase(param);
78+
}
79+
80+
81+
/**
82+
* 修改database
83+
*
84+
* @param request
85+
* @return
86+
*/
87+
@PostMapping("/modify_database")
88+
public ActionResult modifyDatabase(@Valid @RequestBody UpdateDatabaseRequest request) {
89+
DatabaseOperationParam param = DatabaseOperationParam.builder().databaseName(request.getDatabaseName())
90+
.newDatabaseName(request.getNewDatabaseName()).build();
91+
return databaseService.modifyDatabase(param);
92+
}
93+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package ai.chat2db.server.web.api.controller.rdb;
2+
3+
import ai.chat2db.server.domain.api.service.FunctionService;
4+
import ai.chat2db.server.tools.base.wrapper.result.ListResult;
5+
import ai.chat2db.server.web.api.aspect.ConnectionInfoAspect;
6+
import ai.chat2db.server.web.api.controller.rdb.request.TableBriefQueryRequest;
7+
import ai.chat2db.spi.model.Function;
8+
import jakarta.validation.Valid;
9+
import org.springframework.beans.factory.annotation.Autowired;
10+
import org.springframework.web.bind.annotation.GetMapping;
11+
import org.springframework.web.bind.annotation.RequestMapping;
12+
import org.springframework.web.bind.annotation.RestController;
13+
14+
@ConnectionInfoAspect
15+
@RequestMapping("/api/rdb/function")
16+
@RestController
17+
public class FunctionController {
18+
19+
@Autowired
20+
private FunctionService functionService;
21+
22+
23+
@GetMapping("/list")
24+
public ListResult<Function> list(@Valid TableBriefQueryRequest request) {
25+
return functionService.functions(request.getDatabaseName(), request.getSchemaName());
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package ai.chat2db.server.web.api.controller.rdb;
2+
3+
import ai.chat2db.server.domain.api.service.ProcedureService;
4+
import ai.chat2db.server.tools.base.wrapper.result.ListResult;
5+
import ai.chat2db.server.web.api.aspect.ConnectionInfoAspect;
6+
import ai.chat2db.server.web.api.controller.rdb.request.TableBriefQueryRequest;
7+
import ai.chat2db.spi.model.Procedure;
8+
import jakarta.validation.Valid;
9+
import org.springframework.web.bind.annotation.GetMapping;
10+
import org.springframework.web.bind.annotation.RequestMapping;
11+
import org.springframework.web.bind.annotation.RestController;
12+
13+
@ConnectionInfoAspect
14+
@RequestMapping("/api/rdb/procedure")
15+
@RestController
16+
public class ProcedureController {
17+
18+
private ProcedureService procedureService;
19+
20+
@GetMapping("/list")
21+
public ListResult<Procedure> list(@Valid TableBriefQueryRequest request) {
22+
return procedureService.procedures(request.getDatabaseName(), request.getSchemaName());
23+
}
24+
}

chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/RdbDdlController.java

+3
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
@ConnectionInfoAspect
4646
@RequestMapping("/api/rdb/ddl")
4747
@RestController
48+
@Deprecated
4849
public class RdbDdlController {
4950

5051
@Autowired
@@ -183,6 +184,8 @@ public ActionResult modifySchema(@Valid @RequestBody UpdateSchemaRequest request
183184
return databaseService.modifySchema(param);
184185
}
185186

187+
188+
186189
/**
187190
* 查询当前DB下的表columns
188191
* d

0 commit comments

Comments
 (0)