Querying Object Data Using SQL Statements
You can use SQL statements to query data and view data tables in a simple and intuitive manner. This section describes how to use the console, scripts, and flows to query data. Data query is based on objects. This section uses an object named Namespace__Class__CST as an example. Before the query, create fields and add data to the object.
Querying Object Data on the Console
- Log in to the application designer by referring to Logging In to the Application Designer.
- In the navigation pane, choose Console to access the CLI console.
- On the Object Management tab, enter an SQL statement (for example, select Namespace__number__CST from Namespace__Class__CST) in the command input area.
- Click the button to run the SQL statement. The matched fields are displayed.
Figure 1 Querying object data with a SQL statement
Querying Object Data Using a Script
Use a script to query the data in the custom object Namespace__Class__CST.
- Log in to the application designer by referring to Logging In to the Application Designer.
- In the navigation pane, click Logic.
- Click
next to Script. The page for adding a script is displayed.
- Set the script name to search_data and click Add.
Figure 2 Adding the search_data script
- In the script editor, enter the following code and click
:
The script uses the execute API to execute SQL statements. After the script is executed, view the query result on the LOGS tab at the bottom of the page. In the example script, CNAME is the namespace name. Replace it with the actual namespace name.
import * as db from 'db'; import * as es from 'es'; @useObject(['Namespace__Class__CST']) @action.object({ type: "param" }) export class Input { } @action.object({ type: "param" }) export class Output { } @action.object({ type: 'method' }) export class SearchScript { @action.method({ input: 'ParamsInput', output: 'ParamsOutput' }) public run(input: Input): Output { let out = new Output() this.doSearchScript(); return out; } private doSearchScript() { let sql = db.sql(); let sqlTest = "select name,Namespace__number__CST from Namespace__Class__CST " + "where Namespace__number__CST > ?" let result = db.sql().exec(sqlTest, { params: [0] }) console.log("result", result) } }
- Click
in the upper part of the page and click
in the lower right corner of the page to execute the script. On the log tab page, view the execution result.
Querying Object Data Using a Flow
Use the record selection element of a flow to query data in the custom object Namespace__Class__CST.
- Log in to the application designer by referring to Logging In to the Application Designer.
- In the navigation pane, choose Logic.
- Click
next to Flow. The page for adding a flow is displayed.
- Set the label and name to flowSearchData, and click Add.
Figure 3 Setting flow information
- In the flow designer, click
and create variables name and number on the Context pane. The types of the variables are Text and Number, respectively.
Figure 4 Creating variables - In the Basic diagram element directory of the flow, drag Record Select to the canvas.
Figure 5 Dragging Record Select to the canvas
- Configure the object and output by referring to Figure 6.
- Connect the Start and Record Select elements and configure the output parameters.
Figure 7 Configuring the output parameters
- After the configuration is complete, click
in the upper part of the page to save the flow.
- Click
to run the flow.
- Click Run and view the JSON result.
Figure 8 Querying fields of a custom object with a flow
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