indexLookup method

Stream<Map<String, Object?>> indexLookup(
  1. String indexName,
  2. List<Object?> values
)

Stream every row that matches the leading prefix [values] of the indexed columns. For a single-column index, values has one entry — this is point equality. For a composite index, you may supply fewer values than the index has columns to do a prefix probe (e.g. [country] against an (country, city) index).

Returns an empty stream when no such index exists, when any supplied value is null (NULLs aren't indexed), or when nothing matches.

Implementation

Stream<Map<String, Object?>> indexLookup(
    String indexName, List<Object?> values) async* {
  final si = _secondary[indexName];
  if (si == null) return;
  if (values.isEmpty || values.length > si.columns.length) return;
  final bb = BytesBuilder(copy: false);
  for (var i = 0; i < values.length; i++) {
    final v = values[i];
    if (v == null) return;
    bb.add(_encodeIndexValue(v, si.columnTypes[i]));
  }
  final prefix = bb.toBytes();
  final upper = _bumpPrefix(prefix);
  await for (final entry in si.btree.range(
    lower: prefix,
    lowerInclusive: true,
    upper: upper,
    upperInclusive: false,
  )) {
    final bytes = await _heap.get(entry.value);
    if (bytes == null) continue;
    yield _decodeRow(bytes);
  }
}