insert<T extends Table, D> method

void insert<T extends Table, D>(
  1. TableInfo<T, D> table,
  2. Insertable<D> row, {
  3. InsertMode? mode,
  4. UpsertClause<T, D>? onConflict,
})

Inserts a row constructed from the fields in row.

All fields in the entity that don't have a default value or auto-increment must be set and non-null. Otherwise, an InvalidDataException will be thrown.

By default, an exception will be thrown if another row with the same primary key already exists. This behavior can be overridden with mode, for instance by using InsertMode.replace or InsertMode.insertOrIgnore.

onConflict can be used to create an upsert clause for engines that support it. For details and examples, see InsertStatement.insert.

See also:

Implementation

void insert<T extends Table, D>(TableInfo<T, D> table, Insertable<D> row,
    {InsertMode? mode, UpsertClause<T, D>? onConflict}) {
  _addUpdate(table, UpdateKind.insert);
  final actualMode = mode ?? InsertMode.insert;
  final context = InsertStatement<T, D>(_user, table)
      .createContext(row, actualMode, onConflict: onConflict);
  _addContext(context);
}