Skip to content

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.

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
});