Updated on 2025-08-15 GMT+08:00

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

  1. Log in to the application designer by referring to Logging In to the Application Designer.
  2. In the navigation pane, choose Console to access the CLI console.
  3. On the Object Management tab, enter an SQL statement (for example, select Namespace__number__CST from Namespace__Class__CST) in the command input area.
  4. 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.

  1. Log in to the application designer by referring to Logging In to the Application Designer.
  2. In the navigation pane, click Logic.
  3. Click next to Script. The page for adding a script is displayed.
  4. Set the script name to search_data and click Add.

    Figure 2 Adding the search_data script

  5. 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)
        }
    }

  6. 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.

  1. Log in to the application designer by referring to Logging In to the Application Designer.
  2. In the navigation pane, choose Logic.
  3. Click next to Flow. The page for adding a flow is displayed.
  4. Set the label and name to flowSearchData, and click Add.

    Figure 3 Setting flow information

  5. 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

  6. In the Basic diagram element directory of the flow, drag Record Select to the canvas.

    Figure 5 Dragging Record Select to the canvas

  7. Configure the object and output by referring to Figure 6.

    Figure 6 Configuring Record Select

  8. Connect the Start and Record Select elements and configure the output parameters.

    Figure 7 Configuring the output parameters

  9. After the configuration is complete, click in the upper part of the page to save the flow.
  10. Click to run the flow.
  11. Click Run and view the JSON result.

    Figure 8 Querying fields of a custom object with a flow