insert method
PostgrestBuilder
insert(
- dynamic values, {
- ReturningOption returning = ReturningOption.representation,
- @Deprecated('Use `upsert()` method instead') bool upsert = false,
- @Deprecated('Use `upsert()` method instead') String? onConflict,
Performs an INSERT into the table.
By default the new record is returned. Set returning
to minimal if you don't need this value.
postgrest.from('messages').insert({'message': 'foo', 'username': 'supabot', 'channel_id': 1})
Implementation
PostgrestBuilder insert(
dynamic values, {
ReturningOption returning = ReturningOption.representation,
@Deprecated('Use `upsert()` method instead') bool upsert = false,
@Deprecated('Use `upsert()` method instead') String? onConflict,
}) {
method = 'POST';
headers['Prefer'] = upsert
? 'return=${returning.name()},resolution=merge-duplicates'
: 'return=${returning.name()}';
if (onConflict != null) {
url = url.replace(
queryParameters: {
'on_conflict': onConflict,
...url.queryParameters,
},
);
}
body = values;
return this;
}