updateSomeColumnsOf<T> method
Updates one or more columns of the entity T.
columnsToUpadate: names of the columns to update, in the order they appear at the start ofvalues.whereColumns: names of the columns appearing in the WHERE clause, in the order they appear at the end ofvalues.values: values forcolumnsToUpadatefollowed by values forwhereColumns.whereMcop: operator used to join multiple WHERE conditions. Defaults to'AND'. Any SQL boolean operator works:'OR','AND'.
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 {
int affected = 0;
await (await db).transaction((txn) async {
try {
affected = await txn.rawUpdate(
'UPDATE ${T.toString()} '
'SET ${_preparedColumns(columnsToUpadate, ',')} '
'WHERE ${_preparedColumns(whereColumns, whereMcop)}',
_checkForBoolAndDateTime(values),
);
} catch (e, s) {
debugPrint('updateSomeColumnsOf failed: $e\n$s');
}
});
return affected > 0;
}