Orchestrating Data Sources
A data API can contain multiple data sources. Therefore, an API request can call multiple data sources. For example, the query result of the first data source can be used as the parameter of the second data source.
MySQL is used as an example. Assume that the data API contains data source 1 and data source 2, user01 is the data table of data source 1, and user02 is the data table of data source 2. The structures of the two tables are as follows:
Data Source |
Table Name |
Parameter |
---|---|---|
Data source 1 |
user01 |
|
Data source 2 |
user02 |
|
The data source SQL statement is designed as follows:
For data source 1, query the ID of the data record whose name is zhang in table user01. Assume that the return object from data source 1 is default1.
select id from user01 where name='zhang';
For data source 2, go to table user02 and find the data record of user_age corresponding to the ID found in table user01. Assume that the return object from data source 2 is default2.
select user_age from user02 where user_id=${default1[0].id};
${default1[0].id} indicates the query result from data source 1. (default1 indicates the return object from data source 1, and id indicates the query field of data source 1.)
Assume that the data tables user01 and user02 contain the following data records:
user01 |
user02 |
|||
---|---|---|---|---|
id |
name |
user_id |
user_age |
user_sex |
1 |
zhang |
2 |
17 |
Female |
2 |
li |
3 |
18 |
Male |
3 |
wang |
1 |
18 |
Male |
The following response is returned when the data API is called:
{ "default1":[{ "id":1 }], "default2":[{ "user_age":18 }] }
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot