insert<T> method

Future<T> insert<T>({
  1. required List<SupaInsert<B>> records,
  2. required SupaModifier<B, R, T, PostgrestBuilder, PostgrestBuilder> modifier,
  3. Set<SupaColumnBase<B>>? columns,
})

Inserts records into the Supabase table.

records: The list of records to insert.

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

modifier: The modifier to apply to the query.

Implementation

Future<T> insert<T>({
  required List<SupaInsert<B>> records,
  required SupaModifier<B, R, T, PostgrestBuilder<dynamic, dynamic, dynamic>,
          PostgrestBuilder<dynamic, dynamic, dynamic>>
      modifier,
  Set<SupaColumnBase<B>>? columns,
}) async {
  final request = supabaseClient
      .schema(schema)
      .from(tableName)
      .insert(records.map((r) => r.toJSON()).toList());

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

  return (await request) as T;
}