How to retrieve data from a database with Edge SQL and Edge Functions
See how to retrieve data from an existing database (DB) with Edge SQL and Edge Functions.
Go to Edge SQL referenceRequirements
- Azion Edge Functions enabled.
- An active Azion Personal Token.
Creating a database and adding a table
- Create a database by executing the following cURL:
- Add a table named
users
:
- Populate the table with data:
Now, the DB is created and populated with rows.
Creating an edge function to communicate with Edge SQL
- Access Azion Console.
- On the upper-left corner, select Edge Functions in the Edge Libraries section.
- Click the + Edge Function button.
- Choose a name for your function.
- Delete the placeholder function that is inside the code editor.
- Paste the following code:
This edge function was created to communicate with Edge SQL. Now, it’s necessary to instantiate this function in a running edge application:
Go to How to instantiate edge functions in your applicationLearn how to retrieve data effortlessly with Edge Functions. Watch the video below: