Skip to content

scan

scan<K, V>(opts?): DbIterator<K, V>

Defined in: .work/repos/olmdb/src/olmdb.ts:440

Creates an iterator to scan through database entries within the current transaction.

The iterator implements the standard TypeScript iterator protocol and can be used with for…of loops.

The scan covers the half-open range [start, end)start is the inclusive lower bound and end the exclusive upper bound. This holds regardless of direction: reverse only changes the order in which entries are emitted, not which bound is inclusive (so a reverse scan of [start, end) begins at the largest key below end and ends at start).

K = Uint8Array<ArrayBufferLike>

The type to convert keys to (defaults to Uint8Array).

V = Uint8Array<ArrayBufferLike>

The type to convert values to (defaults to Uint8Array).

ScanOptions<K, V> = {}

Configuration options for the scan operation.

DbIterator<K, V>

A DbIterator instance.

If called outside of a transaction context.

With code “INVALID_TRANSACTION” if transaction is invalid or already closed.

With code “KEY_TOO_LONG” if start or end key exceeds maximum allowed length.

With code “ITERATOR_LIMIT” if maximum number of iterators is reached.

With code “OUT_OF_MEMORY” if memory allocation fails.

await transact(() => {
// Iterate over all entries
for (const { key, value } of scan()) {
console.log('Key:', key, 'Value:', value);
}
// Iterate with string conversion
for (const { key, value } of scan({
keyConvert: asString,
valueConvert: asString
})) {
console.log('Key:', key, 'Value:', value);
}
// Iterate with boundaries
for (const { key, value } of scan({
start: "prefix_",
end: "prefix~"
})) {
console.log('Key:', key, 'Value:', value);
}
// Manual iteration control
const iter = scan({ reverse: true });
const first = iter.next();
iter.close(); // Always close when done early
});