create method

Future<int> create(
  1. Insertable<$Dataclass> f(
    1. $CreateCompanionCallback o
    ), {
  2. InsertMode? mode,
  3. UpsertClause<$Table, $Dataclass>? onConflict,
})

Creates a new row in the table using the given function

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.

To apply a partial or custom update in case of a conflict, you can also use an upsert clause by using onConflict. See InsertStatement.insert for more information.

By default, the onConflict clause will only consider the table's primary key. If you have additional columns with uniqueness constraints, you have to manually add them to the clause's DoUpdate.target.

Returns the rowid of the inserted row. For tables with an auto-increment column, the rowid is the generated value of that column. The returned value can be inaccurate when onConflict is set and the insert behaved like an update.

If the table doesn't have a rowid, you can't rely on the return value. Still, the future will always complete with an error if the insert fails.

Implementation

Future<int> create(
    Insertable<$Dataclass> Function($CreateCompanionCallback o) f,
    {InsertMode? mode,
    UpsertClause<$Table, $Dataclass>? onConflict}) {
  return $state.db.into($state._tableAsTableInfo).insert(
      f($state._createCompanionCallback),
      mode: mode,
      onConflict: onConflict);
}