updateWholeObject method

Future<bool> updateWholeObject(
  1. Object newObject,
  2. List<String> whereColumns,
  3. List<Object> values, {
  4. String whereMcop = 'AND',
})

Updates every column of an entity instance except the primary key.

Example:

final ok = await DataAccess.instance.updateWholeObject(
  Person(18, 'M2Sir'),
  ['name'],
  ['Alpha'],
);

Implementation

Future<bool> updateWholeObject(
  Object newObject,
  List<String> whereColumns,
  List<Object> values, {
  String whereMcop = 'AND',
}) async {
  final SqlExecutor executor = await _executor();
  return _guard('updateWholeObject', false, () async {
    final String op = joinOperator(whereMcop);
    final Map<String, dynamic> row = _rowOf(newObject);
    final String sets = row.keys
        .map((String c) => '${quoteIdentifier(c)} = ?')
        .join(', ');
    final int affected = await executor.change(
      'UPDATE ${quoteIdentifier(_tableOf(newObject))} SET $sets '
      'WHERE ${preparedColumns(whereColumns, op)}',
      <Object?>[...row.values.map(toSqlValue), ...toSqlValues(values)],
    );
    return affected > 0;
  });
}