TinyBase

getSliceRowIds

The getSliceRowIds method gets the list of Row Ids in a given Slice, within a given Index.

getSliceRowIds(
  indexId: string,
  sliceId: string,
): Ids
TypeDescription
indexIdstring

The Id of the Index.

sliceIdstring

The Id of the Slice in the Index.

returnsIds

The Row Ids in the Slice, or an empty array.

If the identified Index or Slice do not exist (or if the definition references a Table that does not exist) then an empty array is returned.

Example

This example creates a Store, creates an Indexes object, and defines a simple Index. It then uses getSliceRowIds to see the Row Ids in the Slice (and also the Row Ids in Slices that do not exist).

const store = createStore().setTable('pets', {
  fido: {species: 'dog'},
  felix: {species: 'cat'},
  cujo: {species: 'dog'},
});

const indexes = createIndexes(store);
indexes.setIndexDefinition('bySpecies', 'pets', 'species');

console.log(indexes.getSliceRowIds('bySpecies', 'dog'));
// -> ['fido', 'cujo']
console.log(indexes.getSliceRowIds('bySpecies', 'worm'));
// -> []
console.log(indexes.getSliceRowIds('byColor', 'brown'));
// -> []