update method

Future<bool> update({
  1. dynamic data,
  2. dynamic where,
  3. dynamic tableName,
})

Implementation

Future<bool> update({dynamic data, where, tableName}) async {
  bool success = false;
  await database!.transaction(
    (txn) async {
      try {
        var batch = txn.batch();
        if (data is List) {
          for (Map<String, String> i in data) {
            final Map<String, String> maps = {};
            i.forEach((key, value) {
              maps.addAll({key: value.replaceAll("'", "|_|_|").replaceAll('"', '|-|-|')});
            });
            batch.update(tableName, maps, where: where);
          }
        } else {
          batch.update(tableName, data, where: where);
        }
        await batch.commit(continueOnError: false);
        success = true;
      } catch (_) {
        success = false;
      }
    },
  );
  return success;
}