TinyBase logoTinyBase

hasSlice

The hasSlice method returns a boolean indicating whether a given Slice exists in the Indexes object.

hasSlice(
  indexId: string,
  sliceId: string,
): boolean
TypeDescription
indexIdstring

The Id of a possible Index in the Indexes object.

sliceIdstring

The Id of a possible Slice in the Index.

returnsboolean

Whether a Slice with that Id exists.

Example

This example shows two simple Index existence checks.

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.hasSlice('bySpecies', 'dog'));
// -> true
console.log(indexes.hasSlice('bySpecies', 'worm'));
// -> false