Метод openCursor
- {dynamic ключ,
- Диапазон ключей? диапазон,
- Строка? направление,
- Булево? автопереход}
Создает поток курсоров по записям в этом объектом хранилище.
Поток необходимо вручную продвигать, вызывая Cursor.next после каждого элемента или задавая автопереход в значение true.
var cursors = objectStore.openCursor().listen(
(cursor) {
// ...some processing with the cursor
cursor.next(); // advance onto the next cursor.
},
onDone: () {
// called when there are no more cursors.
print('all done!');
}); Асинхронные операции, не связанные с текущей транзакцией, приведут к автоматическому подтверждению транзакции — вся обработка должна выполняться синхронно, если это не дополнительные асинхронные запросы к текущей транзакции.
Реализация
Stream<CursorWithValue> openCursor(
{key, KeyRange? range, String? direction, bool? autoAdvance}) {
var key_OR_range = null;
if (key != null) {
if (range != null) {
throw new ArgumentError('Cannot specify both key and range.');
}
key_OR_range = key;
} else {
key_OR_range = range;
}
// TODO: try/catch this and return a stream with an immediate error.
var request;
if (direction == null) {
request = _openCursor(key_OR_range);
} else {
request = _openCursor(key_OR_range, direction);
}
return _cursorStreamFromResult(request, autoAdvance);
}
© 2012 the Dart project authors
Licensed under the BSD 3-Clause "New" or "Revised" License.
https://api.dart.dev/stable/2.18.5/dart-indexed_db/ObjectStore/openCursor.html