I have written the following function on supabase to get the appropriate products that do not belong to a restaurant:
create or replace function get_non_restaurant_products(id_arg uuid)
returns setof public.product
language sql
as $$
SELECT *
FROM public.product
WHERE public.product.id NOT IN (
SELECT public.product_restaurant.product_id
FROM public.product_restaurant
WHERE public.product_restaurant.restaurant_id = id_arg AND public.product_restaurant.is_deleted = false
)
$$;
I tested this code and it works when calling it in the Supabase sql editor.
On flutter I know that I have to use the rpc function in order to get the data.
So I have done just that:
var productCollection = await _supabase.rpc('get_non_restaurant_products', params: { 'id_arg': id });
My issue is I am not sure how to access this data after this point since it is of type dynamic. Furthermore until now, in order to access the product information on supabase I have been using the following logic:
var productCollection = await _supabase.from('product').select<List<Map<String, dynamic>>>();
var products = productCollection.map((e) => Product.FromJson(e)).toList();
This gives me access to the data.
How can I make it so I have similar types of data when using rpc?
You can do the following: