Skip to main content

Node-RED tutorial

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

Abstract

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

This tutorial shows how to use FairCom DB with Node-RED to create tables, store data, and retrieve data.

The basic structure of the demo is 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. You can edit the inject nodes and open the JSON editor to see the included JSON.

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

  • Node-RED installed and running.

  1. Import the 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. You should see info about the returned auth token in the debug tab.

  3. Click the createTable inject node.

    This will send JSON describing an "athlete" table and the fields it should include. FairCom DB will create this table. You should see a result object including errorCode: 0 in the debug tab.

  4. Click the createIndex ranking inject node.

    This will send JSON describing an index to add to the table. This index will order records by the ranking field. You should see a result object including errorCode: 0 in the debug tab.

  5. Click the createIndex earnings inject node.

    This will send JSON describing another index to add to the table. This index will ordr records by the earnings field. You should see a result object including errorCode: 0 in the debug tab.

  6. Click the createIndex name inject node.

    This will send JSON describing another index to add to the table. This index ill order records by the name field. The data will be ordered descending, case insensitive, and will filter out records that have "livedpast2000" unset. You should see a result object including errorCode: 0 in the debug tab.

  7. Click the insertRecords inject node.

    This will send JSON describing 6 records of data to be inserted into the table. You should see a result object including errorCode: 0 in the debug tab.

  8. Click the getRecordsByTable inject node.

    This will send JSON requesting records from the table including a table filter that will only include records where ranking 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.

  9. Click the getRecordsInKeyRange name inject node.

    This will send JSON requesting 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.

    This will send JSON requesting records from the table sorted by the earnings index where the indexed value is less than 2,000,000. 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.

    This will send JSON requesting records from teh 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.

    This will send JSON describing 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. There is a deleteTable inject node. If you click this, the table will be deleted.