Updating records

In FL0, updating records in a database is similar to inserting records. The main difference is the need to specify a field, such as ID, that FL0 can use to identify which record to update.

This tutorial uses a to-do list management application as an example to demonstrate how to update a record in a database.

Prerequisites

Step 1: Create a flow

  1. Create an HTTP Request flow.

    1. In the Explorer pane, click Create new.
    2. Select Flow.
    3. Type Update Task.
    4. Tap the Return key.
    5. When a dialog appears, select HTTP Request.
  2. Open the Start component.

  3. From the Method dropdown, select PUT.

  4. In the URL field, enter /task.

  5. From the Input Type dropdown, select Json.

  6. Copy the following JSON Schema into the Input Schema field:

    {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        },
        "isComplete": {
          "type": "boolean"
        }
      }
    }
    
  7. Create a query parameter for specifying the ID of a task.

    1. Under Query String, click the + icon.
    2. In the Name field, enter id.
    3. Enable the Required option.
  8. Click the X icon to close the component.

  9. Click Save.

Step 2: Add an "Update" component to the flow

  1. Drag an Update component into the flow.
  2. Select the component to open it.
  3. From the Table dropdown, select Todo > Tasks.
  4. In the Row ID field, select Start > QueryString: id.
  5. In the first Source field, select Start > Body: name.
  6. In the second Source field, select Start > Body: isComplete.
  7. Click the X icon to close the component.
  8. Click Save.

Step 3: Add an "End" component to the flow

  1. Drag an End component into the Update Task flow.
  2. Select the component to open it.
  3. From the Status Code dropdown, select 200 OK.
  4. From the Content Type dropdown, select application/json.
  5. In the Body field, select Update > Data.
  6. Click the X icon to close the component.
  7. Click Save.

Step 4: Run the flow

  1. Open the Run panel.

  2. In the id field, enter the ID of a task.

  3. Copy the following JSON into the Body field:

    {
      "name": "Walk the dog",
      "isComplete": true
    }
    

    (If you don't include the name property, it will be overridden with an empty value.)

  4. Click Run.

To see the updated data, navigate to the database table or view the logs via the Output tab. (Be sure to enable the Show debug option.)