scan
scan<
K,V>(opts?):DbIterator<K,V>
Defined in: .work/repos/olmdb/src/olmdb.ts:435
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. Supports both forward and reverse iteration with optional start and end boundaries.
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});