mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-03-30 15:08:28 +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
|
||||
* @instance
|
||||
*/
|
||||
const iterator = async function * () {
|
||||
const iterator = async function * ({ amount, reverse } = {}) {
|
||||
const keys = []
|
||||
const iteratorOptions = { amount: amount || -1, reverse: reverse || false }
|
||||
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]) {
|
||||
keys[key] = true
|
||||
yield [key, value]
|
||||
|
@ -78,8 +78,9 @@ const LevelStorage = async ({ path, valueEncoding } = {}) => {
|
||||
* @memberof module:Storage.Storage-Level
|
||||
* @instance
|
||||
*/
|
||||
const iterator = async function * () {
|
||||
for await (const [key, value] of db.iterator()) {
|
||||
const iterator = async function * ({ amount, reverse } = {}) {
|
||||
const iteratorOptions = { limit: amount || -1, reverse: reverse || false }
|
||||
for await (const [key, value] of db.iterator(iteratorOptions)) {
|
||||
yield [key, value]
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user