Skip to main content

Node-RED tutorial

Use Node-RED with FairCom DB to create tables, store data, and retrieve data

This tutorial uses a series of inject nodes configured to send different JSON objects to an HTTPS request node. The response is converted to JSON and sent to a debug node for viewing in the debug tab. These JSON objects contain configuration instructions and data telling FairCom DB what to do. The JSON editor can be used to edit and view the JSON object contents.

  • FairCom DB must be installed and running on the same machine that hosts the Node-RED instance.

  • Node-RED must be installed and running.

  1. Import the <faircom>/drivers/node-red.json.nav/flows.json file contents into a Node-RED flow.

    TutorialNodes.png
  2. Click the "createSession" inject node to connect to FairCom DB and establish a session.

    An auth token is stored in the global context by the "Store Auth Token" function node for reuse in the next steps. Information about the returned auth token is in the debug tab.

  3. Click the "createTable" inject node.

    A JSON object is sent that describes an "athlete" table and the fields it should include. FairCom DB will create this table. A result object with "errorCode: 0" should be in the debug tab.

  4. Click the "createIndex ranking" inject node.

    A JSON object is sent that describes an index to add to the table. This index lists records by the "ranking" field. A result object with "errorCode: 0" should be in the debug tab.

  5. Click the "createIndex earnings" inject node.

    A JSON object is sent that describes another index to add to the table. This index lists records by the "earnings" field. A result object with "errorCode: 0" should be in the debug tab.

  6. Click the "createIndex name" inject node.

    A JSON object is sent that describes another index to add to the table. This index lists records by the "name" field. The data is listed in descending order, case insensitive, and records that have "livedpast2000" unset are filtered out. A result object with "errorCode: 0" should be in the debug tab.

  7. Click the "insertRecords" inject node.

    A JSON object is sent that describes 6 records of data to be inserted into the table. A result object with "errorCode: 0" should be in the debug tab.

  8. Click the "getRecordsByTable" inject node.

    A JSON object is sent that requests records from the table including a table filter that will only include records where "ranking" is less than or equal to 3. A result object is sent that includes table rows inside a "data" array. There should be 3 rows that meet the criteria.

  9. Click the "getRecordsInKeyRange name" inject node.

    A JSON object is sent that requests records from the table sorted by the "name_livedpast2000" index where the indexed value is greater than or equal to "P". You should see a result object that includes table rows inside a "data" array. There should be 2 rows that meet the criteria.

  10. Click the "getRecordsInKeyRange earnings" inject node.

    A JSON object is sent that requests records from the table sorted by the "earnings" index where the indexed value is less than 2000000. You should see a result object that includes table rows inside a "data" array. There should be 2 rows that meet the criteria.

  11. Click the "getRecordsInKeyRange ranking" inject node.

    A JSON object is sent that requests records from the table sorted by the "ranking" index where the indexed value is less than or equal to 3. You should see a result object that includes table rows inside a "data" array. There should be 3 rows that meet the criteria.

  12. Click the "getRecordsUsingSQL" inject node.

    A JSON object is sent that describes a simple SQL query on the table. You should see a result object that includes table rows inside a "data" array. There should be 6 rows that meet the criteria.

  13. To delete the table, click the "deleteTable" inject node.