I know that the query is not simple one let me sho...
# flutter
r
I know that the query is not simple one let me show you
l
Intialize Supabase before using it:
Copy code
dart
import 'package:supabase_flutter/supabase_flutter.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();

  Supabase.initialize(
    url: SUPABASE_URL,
    anonKey: SUPABASE_ANNON_KEY,
    authCallbackUrlHostname: 'login-callback', // optional
    debug: true // optional
  );

  runApp(MyApp());
}
this is my example below
Copy code
dart
Future<void> fUserInfo() async {
    final _client = Supabase.instance.client;
    final userID = _client.auth.user()!.id;
    final selectResponse = await _client
        .from('profiles')
        .select()
        .eq('id', userID)
        .execute();
    if (selectResponse.error == null) {
      final dataList = selectResponse.data[0];
      GetStorage box = GetStorage();
      print(dataList);
    } else {
      return print(selectResponse.error);
    }
  }
'profiles' is the name of the table .eq is the filter. I need column name 'id' to be equal to value 'userID'
r
SELECT * FROM posts where user_id IN(SELECT user_to FROM follow WHERE user_from= ${currentUserUid}) AND privacy= 'My Friends'
This is the query
follow is the table with column user_from (mean follow request from) and user_from(mean follow request to)
i want to get the post of the users whom a user is following
i hope you understand
l
is the query returning results in sql editor?
r
yeah
let me show
l
${currentUserUid} is a variable in flutter?
r
this would be the user id of current user
Here
This query is returning the posts of the user whom current user followed
These are the user whom this user is following
Sorry this one
2 column is the user_from and the 3rd one is user_to
j
Just use 2 queries
First get the user to
r
yeah i am doing that way you its take to mush time first to get the user_id which i am following and then getting posts of them
its taking a lot of time
j
I dont fhink there is any othet way
Like in firebase
r
Up there is the query and i am able to get the post directly but i cann't implement that
This one
l
ok so far the solution is first you need to create a view
Copy code
sql
CREATE VIEW NEW_VIEW AS SELECT * FROM posts where user_id IN(SELECT user_to FROM follow WHERE privacy= 'My Friends';
Then in fultter
Copy code
dart
  // query data
  final selectResponse = await client
      .from('NEW_VIEW')
      .eq('user_from', currentUserUid)
      .execute();
  if (selectResponse.error == null) {
    print('response.data: ${selectResponse.data}');
  }
r
What is view?
l
it's like converting this query into a dynamic table
Copy code
sql
SELECT * FROM posts where user_id IN(SELECT user_to FROM follow WHERE privacy= 'My Friends';
so instead of running this long query all the time to get the results. you can basically call it in this way.
Copy code
sql
SELECT * FROM NEW_VIEW;
r
Ok I will try check it out thanks alot for helping me out Thanks alot😃
l
anytime, let me know how it goes
r
Sure😃
its not working
I tried to use stored procedures its its not working giving error of return type i used return try as record by again error and cann't use other return types
l
I tried to test the rpc with storedprocedure it didnt work for me as well
try VIEW for now, I will try soon again the rpc()
The other guy helped me out
Thank you for helping me 😊
l
let me know if the rpc works in flutter
r
Yeah its working perfectly
l
can you share the code. I tried before it didn't work
r
Yeaah