update<T> method

Future<T> update<T>({
  1. required Set<SupaValue<B, dynamic, dynamic>> values,
  2. required SupaFilter<B> filter,
  3. required SupaModifier<B, R, T, PostgrestBuilder, PostgrestBuilder> modifier,
  4. Set<SupaColumnBase<B>>? columns,
})

Updates records in the Supabase table.

values: The set of values to update.

filter: The filter to apply to the query. This targets the records to update.

columns: The set of columns to fetch. If null, all columns are fetched.

modifier: The modifier to apply to the query.

Implementation

Future<T> update<T>({
  required Set<SupaValue<B, dynamic, dynamic>> values,
  required SupaFilter<B> filter,
  required SupaModifier<B, R, T, PostgrestBuilder<dynamic, dynamic, dynamic>,
          PostgrestBuilder<dynamic, dynamic, dynamic>>
      modifier,
  Set<SupaColumnBase<B>>? columns,
}) async {
  final json = values.fold<Map<String, dynamic>>(
    {},
    (prev, column) => prev..addAll(column.toJSON()),
  );

  final request = supabaseClient
      .schema(schema)
      .from(tableName)
      .update(json)
      .supaApplyFilter(filter);

  if (modifier is! SupaNoneModifier<B, R>) {
    final response = await request
        .select(_generateColumnsPattern(columns))
        .supaApplyModifier(modifier);
    return _castResponse(modifier, response);
  }

  return (await request) as T;
}