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

[Optimization][Data Studio]add getSchemas and getTables api #3735

Merged
merged 1 commit into from
Aug 28, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,49 @@ public Result<List<Schema>> getSchemasAndTables(@RequestParam Integer id) {
return Result.succeed(databaseService.getSchemasAndTables(id));
}

/**
* get all schemas of database
*
* @param id {@link Integer}
* @return {@link Result}< {@link List}< {@link Schema}>>
*/
@Cacheable(cacheNames = "metadata_schema", key = "#id")
@GetMapping("/getSchemas")
@ApiOperation("Get All Schemas And Tables")
@ApiImplicitParam(
name = "id",
value = "DataBase Id",
required = true,
dataType = "Integer",
paramType = "path",
dataTypeClass = Integer.class,
example = "1")
@SaCheckPermission(PermissionConstants.REGISTRATION_DATA_SOURCE_DETAIL_TREE)
public Result<List<Schema>> getSchemas(@RequestParam Integer id) {
return Result.succeed(databaseService.getSchemas(id));
}

/**
* get all tables of schema of database
*
* @param id {@link Integer}
* @return {@link Result}< {@link List}< {@link Schema}>>
*/
@GetMapping("/getTables")
@ApiOperation("Get All Schemas And Tables")
@ApiImplicitParam(
name = "id",
value = "DataBase Id",
required = true,
dataType = "Integer",
paramType = "path",
dataTypeClass = Integer.class,
example = "1")
@SaCheckPermission(PermissionConstants.REGISTRATION_DATA_SOURCE_DETAIL_TREE)
public Result<List<Table>> getTables(@RequestParam Integer id, @RequestParam String schemaName) {
return Result.succeed(databaseService.getTables(id, schemaName));
}

/**
* clear cache of schemas and tables
*
Expand Down
16 changes: 16 additions & 0 deletions dinky-admin/src/main/java/org/dinky/service/DataBaseService.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,22 @@ public interface DataBaseService extends ISuperService<DataBase> {
*/
List<Schema> getSchemasAndTables(Integer id);

/**
* get all schemas of database
*
* @param id {@link Integer}
* @return {@link List}< {@link Schema}>
*/
List<Schema> getSchemas(Integer id);

/**
* get all tables of schema of database
* @param id {@link Integer}
* @param schemaName {@link String}
* @return {@link List}< {@link Table}>
*/
List<Table> getTables(Integer id, String schemaName);

/**
* get columns of table
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,26 @@ public List<Schema> getSchemasAndTables(Integer id) {
return schemasAndTables;
}

@Override
public List<Schema> getSchemas(Integer id) {
DataBase dataBase = getById(id);
Asserts.checkNotNull(dataBase, Status.DATASOURCE_NOT_EXIST.getMessage());
Driver driver = Driver.build(dataBase.getDriverConfig());
List<Schema> schemas = driver.listSchemas();
driver.close();
return schemas;
}

@Override
public List<Table> getTables(Integer id, String schemaName) {
DataBase dataBase = getById(id);
Asserts.checkNotNull(dataBase, Status.DATASOURCE_NOT_EXIST.getMessage());
Driver driver = Driver.build(dataBase.getDriverConfig());
List<Table> tables = driver.listTables(schemaName);
driver.close();
return tables;
}

@Override
public List<Column> listColumns(Integer id, String schemaName, String tableName) {
DataBase dataBase = getById(id);
Expand Down
Loading