mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-10-07 22:57:07 +00:00
Add amount and reverse iterator options to storage iterators
This commit is contained in:
parent
16b3358355
commit
5a73b9cdfb
@ -76,10 +76,11 @@ const ComposedStorage = async (storage1, storage2) => {
|
|||||||
* @memberof module:Storage.Storage-Composed
|
* @memberof module:Storage.Storage-Composed
|
||||||
* @instance
|
* @instance
|
||||||
*/
|
*/
|
||||||
const iterator = async function * () {
|
const iterator = async function * ({ amount, reverse } = {}) {
|
||||||
const keys = []
|
const keys = []
|
||||||
|
const iteratorOptions = { amount: amount || -1, reverse: reverse || false }
|
||||||
for (const storage of [storage1, storage2]) {
|
for (const storage of [storage1, storage2]) {
|
||||||
for await (const [key, value] of storage.iterator()) {
|
for await (const [key, value] of storage.iterator(iteratorOptions)) {
|
||||||
if (!keys[key]) {
|
if (!keys[key]) {
|
||||||
keys[key] = true
|
keys[key] = true
|
||||||
yield [key, value]
|
yield [key, value]
|
||||||
|
|||||||
@ -78,8 +78,9 @@ const LevelStorage = async ({ path, valueEncoding } = {}) => {
|
|||||||
* @memberof module:Storage.Storage-Level
|
* @memberof module:Storage.Storage-Level
|
||||||
* @instance
|
* @instance
|
||||||
*/
|
*/
|
||||||
const iterator = async function * () {
|
const iterator = async function * ({ amount, reverse } = {}) {
|
||||||
for await (const [key, value] of db.iterator()) {
|
const iteratorOptions = { limit: amount || -1, reverse: reverse || false }
|
||||||
|
for await (const [key, value] of db.iterator(iteratorOptions)) {
|
||||||
yield [key, value]
|
yield [key, value]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user