updateBeans method

Future<List<int>> updateBeans (List<Bean> beans)

Implementation

Future<List<int>> updateBeans(List<Bean> beans) async {
  Database db = await this.db;
  try {
    Batch batch = db.batch();
    beans.forEach((Bean bean) {
      bean.setUpdatedTime();
      Map<String, dynamic> sdMap = bean.toSerializableMap();
      batch.update(this.tableName, sdMap,
          where: "_id=?", whereArgs: [bean.identifier]);
      batch.update(this.tableName, bean.toSerializableMap());
    });
    List<dynamic> results = await batch.commit();
    for (int i = 0; i < results.length; i++) {
      beans[i].setLocalId(results[i]);
    }
    return results;
  } catch (e) {
    await this.close();
    throw new Exception(e);
  }
}