multiRemove method

Future<List?> multiRemove(
  1. VoltronArray keys
)
override

Implementation

Future<List<dynamic>?> multiRemove(VoltronArray keys) async {
  var database = await _sqLiteHelper.getDatabase();
  if (database == null) {
    throw 'Database Error';
  }
  try {
    var resultList = <dynamic>[];
    // 批量移除,最多一次性移除MAX_SQL_KEYS行
    for (var keyStart = 0; keyStart < keys.size(); keyStart += kMaxSqlKeys) {
      var keyCount = min(keys.size() - keyStart, kMaxSqlKeys);
      var args = <String>[];
      for (var i = 0; i < keyCount; i++) {
        var keyStr = keys.get<String>(keyStart + i);
        if (keyStr != null) {
          args.add(keyStr);
        }
      }
      var batch = database.batch();
      for (var arg in args) {
        batch.delete(
          _sqLiteHelper.getTableName(),
          where: '${SQLiteHelper.kColumnKey} = ?',
          whereArgs: [arg],
        );
      }
      List<dynamic> result = await batch.commit();
      resultList.addAll(result);
    }
    return resultList;
  } catch (e) {
    LogUtils.e('flutterRender', e.toString());
    return null;
  } finally {}
}