doUpdateSQL method

  1. @override
FutureOr doUpdateSQL(
  1. String entityName,
  2. String table,
  3. SQL sql,
  4. Object id,
  5. Transaction transaction,
  6. DBSQLMemoryAdapterContext connection, {
  7. bool allowAutoInsert = false,
})
override

Implementation

@override
FutureOr doUpdateSQL(String entityName, String table, SQL sql, Object id,
    Transaction transaction, DBSQLMemoryAdapterContext connection,
    {bool allowAutoInsert = false}) {
  if (sql.isDummy) return id;

  var map = _getTableMap(table, true)!;

  var prevEntry = map[id];

  var entry = _normalizeEntityJSON(sql.parametersByPlaceholder,
      entityName: entityName, table: table);

  if (prevEntry == null) {
    if (!allowAutoInsert) {
      throw StateError(
          "Can't update not stored entity into table `$table`: $entry");
    }

    var tablesScheme = tablesSchemes[table];
    var idField = tablesScheme?.idFieldName ?? 'id';

    entry[idField] ??= id;

    map[id] = entry;

    _disposeNextIDCounter(table);
  } else {
    var updated = deepCopyMap(prevEntry)!;
    updated.addAll(entry);

    map[id] = updated;
  }

  _onTablesModification();

  return id;
}