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.
1. Apply database action to the
Learn more about database action
2. Fill out the database action settings
single execution for the current use case. But you can also use database connection if you are planning on calling the database multiple times.
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.
Learn more about iteration/for-each 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.
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
To change the value, use the string actions since the data is in string format.
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
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");
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.