Add & query records
Use Node-RED to add & query records in FairCom Edge
Tutorial to use Node-RED to add & query records in FairCom Edge
Complete the tutorial requirements before this procedure.
Add Records
Drag an inject node into the flow.
Connect the output of the inject node to the input of the Add auth token node that the createTable node feeds into.
Double-click the inject node to edit it.
Enter
insertRocords
in the Name textbox.Enter
{} JSON
in the msg.payload textbox.Click
to open the JSON editor.Paste the following JSON into the JSON editor textbox:
"api": "db", "authToken": "<valid authToken>", "action": "insertRecords", "params": { "databaseName": "ctreeSQL", "tableName": "athlete", "dataFormat": "objects", "sourceData": [ { "name": "Michael Jordan", "ranking": 1, "birthDate": "19630217", "playerNumber": 23, "livedPast2000": true, "earnings": 1700000000, "favoriteSaying": "There is no 'i' in team but there is in win." }, { "name": "Babe Ruth", "ranking": 2, "birthDate": "18950206", "playerNumber": 3, "livedPast2000": false, "earnings": 800000, "favoriteSaying": "Every strike brings me closer to the next home run." }, { "name": "Muhammad Ali", "ranking": 3, "birthDate": "19420117", "playerNumber": 1, "livedPast2000": true, "earnings": 60000000, "favoriteSaying": "Float like a butterfly, sting like a bee." }, { "name": "Pele", "ranking": 4, "birthDate": "19401023", "playerNumber": 10, "livedPast2000": true, "earnings": 115000000, "favoriteSaying": "Everything is practice." }, { "name": "Wayne Gretzky", "ranking": 5, "birthDate": "19610126", "playerNumber": 99, "livedPast2000": true, "earnings": 1720000, "favoriteSaying": "You miss 100 percent of the shots you never take." }, { "name": "Michael Schumacher", "ranking": 6, "birthDate": "19690103", "playerNumber": 1, "livedPast2000": true, "earnings": 990000000, "favoriteSaying": "Once something is a passion, the motivation is there." } ] } }
Click
to close the JSON editor.Click
to save the inject node.
Click FairCom Edge server instructing it to insert 6 records into the table we created.
to configure the inject node to send a JSON object to theClick the corresponding createIndex node button to send the request.
Observe the results in the debug tab.
Note
"errorCode"
with a value of0
indicates success."errorCode"
with a non-zero value indicates a failure. See Errors and contact FairCom for more information about an error.
Query data
Drag an inject node into the flow.
Connect the output of the inject node to the input of the Add auth token node that the createTable node feeds into.
Double-click the inject node to edit it.
Enter
getRecordsStartingAtKey
in the Name textbox.Enter
{} JSON
in the msg.payload textbox.Click
to open the JSON editor.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 } }
Click
to close the JSON editor.Click
to save the inject node.
Click FairCom Edge server instructing it to return records where
to configure the inject node to send a JSON object to the"ranking"
is equal to or greater than three.Click the corresponding createIndex node button to send the request.
Observe the results in the debug tab.
Note
"errorCode"
with a value of0
indicates success."errorCode"
with a non-zero value indicates a failure. See Errors and contact FairCom for more information about an error.Click the
"msg.payload"
object in the debug tab.Expand the
"result"
property.Expand the
"data"
property to view the list of four objects (numbered 0-3).Expand the
0
object to view the first row returned by the query.