Skip to main content

Use Node-RED to add & query records

Prerequisites:

Query data

Figure 1. Flow of nodes
Flow of nodes


  1. Drag an inject node into the flow.

  2. Connect the output of the inject node to the input of the Add auth token node that the createTable node feeds into.

  3. Double-click the inject node to edit it.

    1. Enter getRecordsStartingAtKey in the Name textbox.

    2. Enter {} JSON in the msg.payload textbox.

    3. Click ... to open the JSON editor.

    4. Paste the following JSON in the JSON editor textbox:

      {
          "api": "db",
          "authToken": "replaceWithRealToken",
          "action": "getRecordsStartingAtKey",
          "params": {
              "databaseName": "ctreeSQL",
              "tableName": "athlete",
              "indexFilter": {
                  "indexName": "ranking",
                  "operator": ">=",
                  "indexFields": [
                      {
                          "fieldName": "ranking",
                          "value": 3
                      }
                  ]
              },
              "reverseOrder": false
          }
      }
      
    5. Click Done to close the JSON editor.

  4. Click Deploy to configure the inject node to send a JSON object to the FairCom Edge server instructing it to return records where "ranking" is equal to or greater than three.

  5. Click the corresponding createIndex node button to send the request.

  6. Observe the results in the debug tab.

    Note

    "errorCode" with a value of 0 indicates success. "errorCode" with a non-zero value indicates a failure. See Errors and contact FairCom for more information about an error.

  7. Click the "msg.payload" object in the debug tab.

  8. Expand the "result" property.

  9. Expand the "data" property to view the list of four objects (numbered 0-3).

  10. Expand the 0 object to view the first row returned by the query.

    QueryData.png