Class DataSourceController
java.lang.Object
io.micronaut.controlpanel.panels.datasource.DataSourceController
@Controller("${micronaut.control-panel.path:/control-panel}/datasource-control-panel-controller")
@ExecuteOn("blocking")
@Internal
public final class DataSourceController
extends Object
REST controller to execute SQL queries against a specific DataSource for the Control Panel.
Designed to return paged query results for the Control Panel table renderer.
- Since:
- 2.0.0
- Author:
- Álvaro Sánchez-Mariscal
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordView model for a selected table column.static final recordView model for a table page-size option.static final recordRequest DTO for query execution.static final recordResponse DTO for paged query results with column labels.static final recordView model for a selected table relationship.static final recordView model for the selected datasource table detail.static final recordView model for a datasource table row.static final recordView model for one page of datasource tables. -
Constructor Summary
ConstructorsConstructorDescriptionDataSourceController(io.micronaut.context.BeanLocator locator, io.micronaut.json.JsonMapper jsonMapper) -
Method Summary
Modifier and TypeMethodDescriptionio.micronaut.http.HttpResponse<Object> poolStatus(String dataSource) Renders current datasource pool status as an HTML fragment.io.micronaut.http.HttpResponse<DataSourceController.QueryResponse> query(String dataSource, DataSourceController.QueryRequest body) Execute a SQL query against the specified datasource.io.micronaut.http.HttpResponse<String> Build CodeMirror SQLNamespace with normalized lowercase keys for matching.io.micronaut.http.HttpResponse<Object> tableDetail(String dataSource, @Nullable String schema, String tableName) Renders a single datasource table detail as an HTML fragment.io.micronaut.http.HttpResponse<Object> tables(String dataSource, @Nullable Integer page, @Nullable Integer size, @Nullable String schema, @Nullable String search) Renders one page of datasource tables as an HTML fragment.
-
Constructor Details
-
DataSourceController
public DataSourceController(io.micronaut.context.BeanLocator locator, io.micronaut.json.JsonMapper jsonMapper)
-
-
Method Details
-
schemaJs
@Get(value="/{dataSource}/schema.js", produces="application/javascript") public io.micronaut.http.HttpResponse<String> schemaJs(String dataSource) Build CodeMirror SQLNamespace with normalized lowercase keys for matching.
{ "schema": { "table": { self: {label:"EMP", type:"table"}, children: [{label:"EMPNO", type:"column"}, ...] } } }- Parameters:
dataSource- The name of the datasource- Returns:
- HttpResponse containing the generated schema.js JavaScript
-
tables
@Get(value="/{dataSource}/tables", produces="text/html") public io.micronaut.http.HttpResponse<Object> tables(String dataSource, @QueryValue @Nullable Integer page, @QueryValue @Nullable Integer size, @QueryValue @Nullable String schema, @QueryValue @Nullable String search) Renders one page of datasource tables as an HTML fragment.- Parameters:
dataSource- The name of the datasourcepage- The 1-based page numbersize- The number of tables per pageschema- The schema to filter by, or null for all schemassearch- The table search term, or null for all table names- Returns:
- A server-rendered HTML fragment containing one table page
-
tableDetail
@Get(value="/{dataSource}/tables/detail", produces="text/html") public io.micronaut.http.HttpResponse<Object> tableDetail(String dataSource, @QueryValue @Nullable String schema, @QueryValue("table") String tableName) Renders a single datasource table detail as an HTML fragment.- Parameters:
dataSource- The name of the datasourceschema- The table schematableName- The table name- Returns:
- A server-rendered HTML fragment for the selected table
-
poolStatus
@Get(value="/{dataSource}/pool/status", produces="text/html") public io.micronaut.http.HttpResponse<Object> poolStatus(String dataSource) Renders current datasource pool status as an HTML fragment.- Parameters:
dataSource- The name of the datasource- Returns:
- A server-rendered HTML fragment for the current pool status
-
query
@Post(value="/{dataSource}/query", produces="application/json") public io.micronaut.http.HttpResponse<DataSourceController.QueryResponse> query(String dataSource, @Body DataSourceController.QueryRequest body) Execute a SQL query against the specified datasource.- Parameters:
dataSource- The name of the datasource (path parameter)body- The query request containing SQL and pagination parameters- Returns:
- The query results as a
HttpResponsecontainingDataSourceController.QueryResponse, or an error response if the query fails
-