insert method

PostgrestBuilder insert(
  1. dynamic values, {
  2. ReturningOption returning = ReturningOption.representation,
  3. @Deprecated('Use `upsert()` method instead') bool upsert = false,
  4. @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;
}