insert method

Future<bool> insert({
  1. dynamic data,
  2. dynamic tableName,
})

Implementation

Future<bool> insert({dynamic data, 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) {
              final parse = value.replaceAll("'", "|_|_|").replaceAll('"', '|-|-|');
              maps.addAll({key: parse});
            });
            batch.insert(tableName, maps);
          }
        } else {
          batch.insert(tableName, data);
        }
        await batch.commit(continueOnError: false);
        success = true;
      } catch (_) {
        success = false;
      }
    },
  );
  return success;
}