updateSomeColumnsOf<T> method

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

Updates one or more columns of the entity T.

  • columnsToUpadate: names of the columns to update, in the order they appear at the start of values.
  • whereColumns: names of the columns appearing in the WHERE clause, in the order they appear at the end of values.
  • values: values for columnsToUpadate followed by values for whereColumns.
  • whereMcop: operator used to join multiple WHERE conditions: 'AND' (default) or 'OR'.

Example:

final ok = await DataAccess.instance.updateSomeColumnsOf<Person>(
  ['salary', 'married', 'year'],
  ['name'],
  [9000000, true, 45, 'Alpha'],
);

Implementation

Future<bool> updateSomeColumnsOf<T>(
  List<String> columnsToUpadate,
  List<String> whereColumns,
  List<Object> values, {
  String whereMcop = 'AND',
}) async {
  final SqlExecutor executor = await _executor();
  return _guard('updateSomeColumnsOf', false, () async {
    final String op = joinOperator(whereMcop);
    final int affected = await executor.change(
      'UPDATE ${quoteIdentifier(_tableFor<T>())} '
      'SET ${preparedColumns(columnsToUpadate, ',')} '
      'WHERE ${preparedColumns(whereColumns, op)}',
      toSqlValues(values),
    );
    return affected > 0;
  });
}