upsert<T> method
Future<T>
upsert<T>({
- required List<
SupaInsert< records,B> > - required SupaModifier<
B, R, T, PostgrestBuilder, PostgrestBuilder> modifier, - SupaFilter<
B> ? filter, - Set<
SupaColumnBase< ? columns,B> >
Updates or inserts records in the Supabase table.
records
: The list of records to update or insert.
filter
: The filter to apply to the query. This targets the records
fetched after the upsert.
columns
: The set of columns to fetch. If null, all columns are
fetched.
modifier
: The modifier to apply to the query.
Implementation
Future<T> upsert<T>({
required List<SupaInsert<B>> records,
required SupaModifier<B, R, T, PostgrestBuilder<dynamic, dynamic, dynamic>,
PostgrestBuilder<dynamic, dynamic, dynamic>>
modifier,
SupaFilter<B>? filter,
Set<SupaColumnBase<B>>? columns,
}) async {
var request = supabaseClient
.schema(schema)
.from(tableName)
.upsert(records.map((r) => r.toJSON()).toList());
if (filter != null) request = request.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;
}