update method

  1. @override
Future<int> update({
  1. required Filter where(
    1. TMeta t
    ),
  2. TEntity? entity,
  3. Map<ColumnDefinition<IEntity, dynamic>, dynamic> columnValues(
    1. TMeta t
    )?,
  4. bool? useIsolate,
})
inherited

Implementation

@override
Future<int> update({
  required Filter Function(TMeta t) where,
  TEntity? entity,
  Map<ColumnDefinition, dynamic> Function(TMeta t)? columnValues,
  final bool? useIsolate,
}) async {
  assert(entity != null || columnValues != null);
  final db = await dbContext.database;
  final formattedQuery = await whereString(where, useIsolate);
  var createdAt = entity?.createdAt;
  if (entity == null) {
    final res = await firstWhereOrNullMap(
        where: where, columns: (t) => [t.createdAt]);
    if (res?.containsKey(t.createdAt.name) == true) {
      createdAt = DateTime.parse(res![t.createdAt.name]);
    }
  }
  entity = (entity ?? mType).updateDates(createdAt: createdAt) as TEntity;
  final update = columnValues != null
      ? entity.toStorageJson(columnValues: columnValues(t))
      : entity.toDb();
  return await db.update(
    t.tableName,
    update,
    where: formattedQuery.filter,
    whereArgs: formattedQuery.whereArgs,
  );
}