Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Log into the management console and click Create under Data Service.
  2. Add a name for the data service and go to the next step.
  3. Connect to the Company database that you defined above. For information on how to connect to a RDBMS, see Adding an RDBMS datasource.
  4. Click Next to open the Queries screen.
  5. Click Add New Query to specify the query details:
    1. Enter EmployeeOfficeSQL as the query ID.

    2. Enter the following SQL dialect:

      Code Block
      select EmployeeNumber, FirstName, LastName, Email, JobTitle, OfficeCode from EMPLOYEES where OfficeCode=:OfficeCode
  6. Generate input and output mappings:
    1. Click Generate Input Mapping and an input mapping will be generated automatically for the OfficeCode field:
    2. Click Generate Response to automatically generate output mappings for the EmployeeNumberFirstNameLastNameEmailJob Title and Office Code fields.
  7. Save the EmployeeOfficeSQL query.

  8. Start creating a new query for the Company datasource:

    1. Enter listOfficeSQL as the query ID.

    2. Enter the following SQL dialect:

      Code Block
      select OfficeCode, AddressLine1, AddressLine2, City, State, Country, Phone from OFFICES
  9. Click Generate Response to create output mappings for the fields specified in the above query.
  10. Click Add New Output Mapping and specify the required values for the fields.

    1. Select Query for the Mapping Type field.

    2. Enter the employeeOfficeSQL query you created previously in the Select Query field.

    3. Save the output mapping

  11. Save the listOfficeSQL query.

    Info

    Handling nested queries in a JSON output

    Nested queries can be mentioned in the JSON mapping by giving the query details as a JSON object attribute. That is, the name of the target query to be called and the property value (the fields in the result mapped with the target query parameters) are included in the JSON mapping as the object attribute name. Example:

    Code Block
    languagejavascript
    titleJSON Mapping with Nested Queries
    {
        "Offices": {
            "Office": [
                {
                    "OfficeCode": $OfficeCode(type:integer),
                    "City": "$City",
                    "Country": "$Country",
                    "Phone": "$Phone",
                    "EmployeeOfficeSQL@EmployeeOfficeSQL": "$OfficeCode->OfficeCode"
                }
            ]
        }
    }

    In the nested query mapping,

    • The target query name is mentioned by prefixing the query name with "@". Note "@EmployeesOfficeSQL@EmployeeOfficeSQL" in the example given above.
    • The parameter mapping is added to the query by giving the following values: The field name in the result prefixed by "$", and the name of the target query parameter.
    • These two values in the parameter mapping are separated by "->". See "$OfficeCode->OfficeCode" in the example given above.
    • Note that the target query name and the parameter mapping are separated by a colon as follows: "@EmployeeOfficeSQL": "$OfficeCode->OfficeCode"
  12. Click Next to open the Operations screen.
  13. Create an operation for the listOfficeSQL query as shown below:
  14. Save the listOfficeSQLOP operation.

  15. Click Finish to navigate to the Deployed Services window, from where you can manage data services.

...