Can some help me how to implement query like this ...
# off-topic
r
Can some help me how to implement query like this one?
2nd from is of user_from user uid of user and 3rd row is user_to uid of user who he is following
s
Is the user uuid always the same one or is it a parameter that you pass in?
Same question for privacy too
u
^
r
Yeah that i written here would be the current user uid
Mean it is the query to get posts of whom a current user is following
s
So this uuid would be dynamic and not static right?
r
Privacy will also be the same
Yeah dynamic
I have written static to check is the query works
s
The best way to do this is to create a database function and call it via the
.rpc
method on the SDK
I can’t give an example right now as I’m on my mobile, but if you check the Supabase GitHub discussion board you will find examples I’ve given in the past. Just search for .rpc and you should get some results
r
Ok i will check 😊
k
you could simply do this:
Copy code
final response = await _supabase.client
        .from('posts')
        .select(
          "*, user:user_id(id, username, profile_picture)"
        )
        .eq('user_id', uid)
        .execute();
for friends table, my table is designed in a way like this friends_table -> follower , following, created_at, both follower and following are primary keys. then simply to get followers from supabase
Copy code
final response = await _supabase.client
        .from(FRIENDS_DB)
        .select(
          "*, following_user:follower(id, username, profile_picture), "
          "follower_user:following(id, username, profile_picture)",
        )
        .eq('following', uid)
        .execute();
to get followings
Copy code
final response = await _supabase.client
        .from(FRIENDS_DB)
        .select(
          "*, follower_user:follower(id, username, profile_picture), "
          "following_user:following(id, username, profile_picture)",
        )
        .eq('follower', uid)
        .execute();
r
Hey I made rpc method but having issue in return type can you help me out
s
Open an Discussion on https://github.com/supabase/supabase/discussions and I will assist you there
@User I've replied to your discussion topic I'll paste the link here for anyone wanting to get involved or having the same question https://github.com/supabase/supabase/discussions/2741
@User can you modify the title to How do I get query data from a database function?
r
Sure and thanks alot sir😊
s
You're welcome, I'm sure this will be useful to someone else in the future too. At some point I will try and work out how to do this with the actual function UI in the dashboard.
r
sure it would be very helpful