Link Search Menu Expand Document
Course 1: Getting started with API AutoFlow

2 min read · 6 min video

Lesson 6: Learn How to Work with Databases

Now with a good understanding of iteration, you can start working with the database. A database returns a list of records in an array format.

Prerequisite:

Lesson Outline

  1. Apply database action to the flow
  2. Fill out the database action settings
  3. Apply the iteration actions

1. Apply database action to the flow

Apply database action

Learn more about database action

2. Fill out the database action settings

Use single execution for the current use case. But you can also use database connection if you are planning on calling the database multiple times.

Fill out database action

3. Apply the iteration/foreach actions

The database returns the data in an array. Use iteration action to loop over the array.

For this use case, we will use iteration/for-each action to apply actions for each of the items in the array.

Apply iteration for each

Learn more about iteration/for-each action

4. Create an empty array by applying a data/set action

In most use cases, the data from the database needs to be transformed into another format.

Use data/set action to create an empty array to store the newly looped data.

Create an empty array

5. Put together a new dataset by applying an array/insert-at action

For each item, use array/insert-at action to insert the newly formed data in the empty array that was created in the previous step.

Note that the action is creating a new object with a new object key.

To change the value, use the string actions since the data is in string format.

Use array insert at

Learn more about array/insert-at action

6. Put together a response by applying a data/set action

Finally, to provide the data for others to use, final data needs to be provided in the response/body.

Put together HTTP response

Download Learn How to Work with Databases configuration

Learn how to use configuration

Create DATABASE

How to install MySQL

MySQL example

CREATE DATABASE patients;
USE patients;
CREATE TABLE patient(
    id                BIGINT             AUTO_INCREMENT,
    name              VARCHAR(255)       NOT NULL,
    dob               VARCHAR(255)       NOT NULL
);

INSERT INTO patients.patient (name, dob) VALUES ("Peter Jung", "1990-01-01");

Advanced

Use Database Connection

When you are using the same database connection multiple times, you can create the connection once and apply to use the use database connection type.

1. Create database connection

Create database connection

2. Fill in the database connection details

Fill in the database connection details

3. Check that the database connection is established

Check database connection

4. Select use database connection type

Select database-id

Selece use database connection

Download Learn How to Work with Database Connection configuration

Learn how to use configuration

NEXT » Lesson 7: Reusable Custom Actions, Files, and Data. Cut and Paste Configurations