Counting records in Supabase

Database & APIs
Resolved

I want to make a Custom Action to count the number of records in the table by condition.

What have you tried so far?

In my Dart code, I do it like this:

final response = await supabase
      .from('chat_messages')
      .select('*')
      .eq('user_to', '12345')
      .count();

print(response.count);

If I do the same thing in Custom Action I get an error (

Future<int> countChatNewMessages(
  String userId,
) async {
  final supabase = SupaFlow.client;

  final response = await supabase
      .from('chat_messages')
      .select('*')
      .eq('user_to', userId)
      .count();

  return response.count;
}

Please help me solve it.

Update

Here is my solution:

Future<int?> countChatNewMessages(
  String userId,
) async {
  final supabase = SupaFlow.client;

  final response = await supabase
      .from('chat_messages')
      .select(
        '*',
        const FetchOptions(
          count: CountOption.exact,
        ),
      )
      .eq('user_to', userId);

  return response.count;
}
Did you check FlutterFlow's Documentation for this topic?
Yes