updateOrThrow<T extends TableBase> method

Future<int?> updateOrThrow<T extends TableBase>(
  1. T obj
)

Implementation

Future<int?> updateOrThrow<T extends TableBase>(T obj) async {
  if (_dbModel!.preSaveAction != null) {
    obj = await _dbModel!.preSaveAction!(_tableName!, obj) as T;
  }
  final data = obj.toMap(forQuery: true);
  if (openedBatch[_dbModel!.databaseName] == null) {
    final Database? db = await this.db;
    final result = await db?.update(_tableName!, data,
        where: _whereStr, whereArgs: buildWhereArgs(data));
    obj.saveResult = BoolResult(
        success: true,
        successMessage:
            '$_tableName-> ${_primaryKeyList![0]} = ${data[_primaryKeyList![0]]} saved successfully');
    return result;
  } else {
    openedBatch[_dbModel!.databaseName]?.update(_tableName!, data,
        where: _whereStr, whereArgs: buildWhereArgs(data));
    obj.saveResult = BoolResult(
        success: true,
        successMessage: '$_tableName-> update: added to batch successfully');
    return 0;
  }
}