Not only a leakage of data but also a waterfall of requests that will slow down the load of your quiz (wait for first query and then wait for the second query with the data you need).
With supabase you can create database functions that allow you to do get a random row with only one request.
Have a look at the documentation.
In short:
- create and run this SQL snippet:
create or replace function get_random_quiz()
returns setof quiz
language sql
as $$
select * from quiz
order by random()
limit 1;
$$;
- call the supabase REST API in your workflow with a GET request to the url
https://<project_ref>.supabase.co/rest/v1/rpc/get_random_quiz
. Be sure to switch on the option to make the request with the server and to add two header to the request:- apikey: <SUPABASE_ANON_KEY>
- Authorization: Bearer <SUPABASE_ANON_KEY>
This specific way of getting a random row (order by random()
) is good only for small tables. If you are going to work with big tables you can modify the query to randomly select in a more performant way.