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).
Type Parameters
Section titled “Type Parameters”K = Uint8Array<ArrayBufferLike>
The type to convert keys to (defaults to Uint8Array).
V = Uint8Array<ArrayBufferLike>
The type to convert values to (defaults to Uint8Array).
Parameters
Section titled “Parameters”ScanOptions<K, V> = {}
Configuration options for the scan operation.
Returns
Section titled “Returns”DbIterator<K, V>
A DbIterator instance.
Throws
Section titled “Throws”If called outside of a transaction context.
Throws
Section titled “Throws”With code “INVALID_TRANSACTION” if transaction is invalid or already closed.
Throws
Section titled “Throws”With code “KEY_TOO_LONG” if start or end key exceeds maximum allowed length.
Throws
Section titled “Throws”With code “ITERATOR_LIMIT” if maximum number of iterators is reached.
Throws
Section titled “Throws”With code “OUT_OF_MEMORY” if memory allocation fails.
Example
Section titled “Example”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});