How to transform query into function. - Supabase