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,
})

Implementation

@override
Future<int> update({
  required Filter Function(TMeta t) where,
  TEntity? entity,
  Map<ColumnDefinition, dynamic> Function(TMeta t)? columnValues,
  final bool? useIsolate,
}) async {
  var query = where(t)
      .filters
      .where((element) => element.column?.name == 'id')
      .toList();
  if (query.isNotEmpty == true) {
    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 = res![t.createdAt.name];
      }
    }
    entity = (entity ?? mType).updateDates(createdAt: createdAt) as TEntity;
    final update = columnValues != null
        ? entity.toStorageJson(columnValues: columnValues(t))
        : entity.toMap();
    await write(key: query[0].value, value: update);
    return 1;
  }
  return 0;
}