(self)
| 108 | @expose('/queryTableData', methods=("GET",)) |
| 109 | @safe |
| 110 | def get_table_data(self) -> FlaskResponse: |
| 111 | data_source_name = request.args.get('dataSourceName') |
| 112 | database = request.args.get('database') |
| 113 | table_name = request.args.get('tableName') |
| 114 | type_name = request.args.get('typeName', default=None) |
| 115 | # Call the service method to get table data. You need to implement this logic |
| 116 | data_source = DataSourceDAO.get_data_source_name(data_source_name) |
| 117 | if data_source is None: |
| 118 | return self.handle_error(SolidUIErrorType.QUERY_DATASOURCE_ERROR) |
| 119 | |
| 120 | data_source_type = DataSourceTypeDAO.get_id(data_source.datasource_type_id) |
| 121 | if data_source_type is None: |
| 122 | return self.handle_error(SolidUIErrorType.QUERY_DATASOURCE_TYPE_ERROR) |
| 123 | |
| 124 | # Parse the JSON parameters |
| 125 | params = json.loads(data_source.parameter) |
| 126 | |
| 127 | # Create a JDBC client |
| 128 | jdbc_client = JdbcClientFactory.create_client( |
| 129 | db_type=data_source_type.name, # Assuming MySQL for example |
| 130 | host=params.get("host"), |
| 131 | port=params.get("port"), |
| 132 | username=params.get("username"), |
| 133 | password=params.get("password"), |
| 134 | database=params.get("database"), |
| 135 | extra_params=params.get("params", {}) |
| 136 | ) |
| 137 | |
| 138 | select_all_data_sql = jdbc_client.generate_select_all_data_sql(database, table_name) |
| 139 | select_result = JdbcClientFactory.run_query(jdbc_client, select_all_data_sql) |
| 140 | |
| 141 | # Transform the result into the desired format |
| 142 | if not select_result or len(select_result) == 1: |
| 143 | return self.handle_error(SolidUIErrorType.QUERY_METADATA_SQL_ERROR) |
| 144 | |
| 145 | field_value_results = [] |
| 146 | columns = select_result[0] |
| 147 | for row in select_result[1:]: |
| 148 | field_value_results.append(dict(zip(columns, row))) |
| 149 | |
| 150 | return self.response_format(data=field_value_results) |
| 151 | |
| 152 | @expose('/querySql', methods=("GET",)) |
| 153 | @safe |
nothing calls this directly
no test coverage detected