upsert method
PostgrestBuilder
upsert(
- dynamic values, {
- ReturningOption returning = ReturningOption.representation,
- String? onConflict,
- bool ignoreDuplicates = false,
Performs an UPSERT into the table.
By default the new record is returned. Set returning
to minimal if you don't need this value.
By specifying the onConflict
query parameter, you can make UPSERT work on a column(s) that has a UNIQUE constraint.
ignoreDuplicates
Specifies if duplicate rows should be ignored and not inserted.
postgrest.from('messages').upsert({'id': 3, message: 'foo', 'username': 'supabot', 'channel_id': 2})
Implementation
PostgrestBuilder upsert(
dynamic values, {
ReturningOption returning = ReturningOption.representation,
String? onConflict,
bool ignoreDuplicates = false,
}) {
method = 'POST';
headers['Prefer'] =
'return=${returning.name()},resolution=${ignoreDuplicates ? 'ignore' : 'merge'}-duplicates';
if (onConflict != null) {
url = url.replace(
queryParameters: {
'on_conflict': onConflict,
...url.queryParameters,
},
);
}
body = values;
return this;
}