update method

Future<DbResponse> update({
  1. required Map<String, dynamic> update,
  2. required Where? where,
})
update(
  update: {
    "column1": "new value",
    "age": 60
  },
  where: Where("id", WhereOperator.isEqual, 12)
);

Implementation

Future<DbResponse> update({
  required Map<String, dynamic> update,
  required Where? where,
}) async {
  // ignore: no_leading_underscores_for_local_identifiers
  List<String> _values = [];

  for (var key in update.keys) {
    String val = update[key] is String
        ? "'${update[key]}'"
        : update[key] is List
            ? "'${_listValue(update[key])}'"
            : update[key].toString();
    _values.add('"$key" = $val');
  }
  if (_values.isEmpty) return DbResponse([], []);

  // ignore: no_leading_underscores_for_local_identifiers
  String _value = _values.join(', ');

  String query = ' UPDATE "$tableName" SET $_value ${getQuery(
    where: where,
  )}';
  var dbRes = await db.query(query);

  return DbResponse(
      dbRes.columnDescriptions.map((e) => e.columnName).toList(),
      List<List>.from(dbRes.toList()));
}