I'm trying to display the rest-api response on reactjs front-end.
For instance, my rest-api endpoint is :
<http://url/searchquery/<db_name>/<sql_query>
a live example would be:
http://127.0.0.1:5002/sqlquery/A123vSearch/SELECT DATE,LABEL_NUMBER,FILENAME FROM FILE_INFO_SEARCH WHERE FILENAME MATCH 'C:/Test_Software/opencv_world320.dll'
In the above example, i have two questions:
1) How would i ask user to input two variable values (1 for db_name and 1 for sql_query) ? Should i use two input box or should i use '/' slash separator in one single box, which is easier to maintain?
2) If someone changes the sql_query from SELECT DATA, LABEL_NUMER
TO SELECT *
How, would i display all the table list in the webpage?
Here is my current 'SearchQuery.js' file
export default class SearchQuery extends React.Component{
constructor(){
super();
this.state = {
query : "SELECT DATE,LABEL_NUMBER,FILENAME FROM FILE_INFO_SEARCH WHERE FILENAME MATCH 'opencv_world320.dll'",
};
}
componentDidMount(){
this.SearchQuery();
}
updateSearch(){
this.setState({query: this.refs.query.value});
this.SearchQuery(this.refs.query.value);
}
render(){
var tables = _.map(this.state.tables, (table) => {
return <li>{table.FILENAME}</li>;
return <div align="center">
<br/><br/>
<input ref="query" onChange={(e) => {this.updateSearch();}} type="text" value={this.state.query} />
<br/><br/>
<ul>{tables}</ul>
</div>;
}
SearchQuery(query = "SELECT DATE,LABEL_NUMBER,FILENAME FROM FILE_INFO_SEARCH WHERE FILENAME MATCH 'opencv_world320.dll'"){
var url = `http://127.0.0.1:5002/sqlquery/AvSearch/${query}`;
Request.get(url).then((response) => {
console.log(response);
this.setState({
tables: response.body.output,
total: response.body.totalResults
});
});
}
}
The above code works fine if i use the standard Query that i have mentioned in the Live Example but doesn't work, if i use the query as 'SELECT *'
Here is my api-response:
{
"output": [
{
"CLIENT_NAME": "dusii",
"FILENAME": "C:/Test_Software/opencv_world320.dll",
"FILE_DATE": "2016-12-23 15:56:17",
"LABEL_NUMBER": "11",
"PERM": "----------",
"SIZE": "39.91 MB",
"USER": "srt/None"
},
}
I know that something needs to be changed to display an array of items in table form, its just that i don't know how to do that...something at this line <li>{table.FILENAME}</li>