Create a table & index
Use Node-RED to create a table & index in FairCom Edge
Tutorial to use Node-RED to create a table & index in FairCom Edge
Complete the tutorial requirements before this procedure.
Create table
Drag an inject node into the flow.
Double-click the inject node to edit it.
Enter
createTable
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": "createTable", "params": { "databaseName": "ctreeSQL", "tableName": "athlete", "fields": [ { "name": "name", "type": "varchar", "length": 30 }, { "name": "ranking", "type": "smallint", "nullable": false }, { "name": "birthDate", "type": "date" }, { "name": "playerNumber", "type": "number", "length": 32, "scale": 6 }, { "name": "livedPast2000", "type": "bit" }, { "name": "earnings", "type": "money", "length": 32, "scale": 4 }, { "name": "favoriteSaying", "type": "varchar", "length": 500 } ] } }
Click
to close the JSON editor.Click
on the inject node.
Drag a function node into the flow.
Connect the output of the createTable inject node to the input of the function mode.
Double-click the function node to edit it.
Enter
Add auth token
in the Name textbox.Paste the following code in the On Message code editor textbox:
var authToken = flow.get("tutorial_authToken")||"BadToken"; msg.payload.authToken = authToken; return msg;
Click
to finish configuring the node and to close the node editor.Note
This node will now replace the
"authToken"
property of the JSON object it receives with the real auth token stored in a flow variable.
Copy the http request node and paste a duplicate of it into the flow.
Connect the output of the Add auth token node to the input of the request node.
Drag in a JSON node and connect the output from the request node to the input of the JSON node.
Drag a debug node into the flow.
Connect the output of the JSON node to the input of the debug node.
Note
This will send the results of the request to the debug tab where it is easily inspected.
Click
.Click the corresponding createTable node button to send the request.
Observe the results in the debug tab in a JSON payload object and an empty table in the FairCom Edge server.
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.
Create index
Add an Inject node and connect the output of the inject node to the input of the Add auth token node from above.
Enter
createIndex
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": "createIndex", "params": { "databaseName": "ctreeSQL", "tableName": "athlete", "indexName": "ranking", "fields": [ { "name": "ranking" } ], "waitToBeLoaded": true } }
Click
to close the JSON editor.Click
on the inject node.Click FairCom Edge server instructing it to add an index to the created table.
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 in a response object and a new index on ranking in the created table.
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.