Hi guys, how can i turn this sql statement into an...
# help
r
Hi guys, how can i turn this sql statement into an API request, I've tried with or, match, eq and I can't get it to work
Copy code
select * from lista_amigo
where (id_usuario1 = '5f97caf5-4e91-4583-adcb-9404d30c7403' and id_usuario2= 'b8de25ee-3867-412c-89c0-f3a865597efa')
or (id_usuario2 = '5f97caf5-4e91-4583-adcb-9404d30c7403' and id_usuario1= 'b8de25ee-3867-412c-89c0-f3a865597efa')
g
Docs have an example: const { data, error } = await supabase .from('cities') .select('name, country_id') .or('id.gt.20,and(name.eq.New Zealand,name.eq.France)')
Does .or('and(id1.eq.xx,id2.eq.yy),and(id12.eq.xy,id1.eq.yx)') not work?
r
tried exactly that but doesnt work
g
just to make sure a normal select work just on a single id?
r
with a single id works fine
i'm doing a friend like system, so i have this model
where perfil_usuario contains my user data, and lista_amigo is the friends list
g
so just glancing at your id's you are asking if both ids are set to either uuid at same time
r
yes, to get the friend list of a specific user the user id needs to be in either user id from the friend list
g
did you run that select from the sql ui
r
it works
this is for a specific user to check if the friend request was accepted (column confirmado)
g
I've not used the .or(and(),and()) but not sure why it would not work. I would next guess RLS, but you tested that with single id. No idea then.
r
RLS is not activated
I can continue if this doesn't work, after this i need to show the user data from the users table, and that isn't working either
g
I guess you should check the URL being generated to send to postgrest looks OK.
r
Copy code
const { data: amigos, error } = await supabase
                    .from("lista_amigo")
                    .select()
                    .or(
                        `id_usuario1.eq.${
                            supabase.auth.user().id
                        }, id_usuario2.eq.${supabase.auth.user().id}`
                    )
                    .eq('lista_amigo.confirmado', true);
this work fine
but i can't join this with the user table, cuz there is a double join with the user table
i can only get one side but that will only work for the user that receives the friend request
g
I get a headache trying that. I don't know how else your friend table is used but you might think about an array for the two ids then you just see if it CONTAINS(id). Or having an entry for each friend of a person (so two entries with the primary id first and friend Id second. But of course could mess up something else you use that for.
r
yeah I got lots of headaches cuz of that, i'll try the array thing
thanks