0

How do I make the following query in supabase on a stream listening for changes:


select * from public.messages where "to" IS NOT NULL;

From the documentation the closest, I could get was doing the filtering with an "equal to" expression. As captured below:


_messagesStream = supabase
        .from('messages:to=eq.123')
        .stream(['id'])
        .order('created_at')
        .execute()
        .map((maps) => maps
            .map((map) => Message.fromMap(map: map, myUserId: myUserId))
            .toList());

But what I need is a query with "IS NOT NULL". A work around I found was to handle complex queries in a view, but the issue here is, I cannot listen for events on view.

Kindly assist.

The Nerdy Geek
  • 342
  • 5
  • 16
  • As @igdmitrov has answered, there is no `is not` filter in `stream()` method as there is no such methods in Supabase realtime at the moment. `stream()` uses Supabase realtime engine under the hood. – dshukertjr Jul 25 '22 at 02:42

2 Answers2

2

I think it is not possible. I checked supabase.dart and I can't find any solution on how to implement it.

But you can filter it on your side:

 _messagesStream = supabase
        .from('messages:to=eq.123')
        .stream(['id'])
        .order('created_at')
        .execute()
        .map((maps) => maps
           .where((element) => element['to'] != null)
            .map((map) => Message.fromMap(map: map, myUserId: myUserId))
            .toList());  
igdmitrov
  • 476
  • 1
  • 3
  • 10
0

From Supabase docs / Filters / is()

    const { data, error } = await supabase
    .from('countries')
    .select()
    .is('name', null)
eXnihilo
  • 9
  • 2