TinyBase logoTinyBase β

getIndexStoreTableId

The getIndexStoreTableId function returns the Store and table Id for a given Indexes object and index Id.

getIndexStoreTableId(
  indexesOrId: MaybeGetter<undefined | IndexesOrIndexesId>,
  indexId: MaybeGetter<string>,
): {
  store: Store | undefined;
  tableId: Id | undefined;
}
TypeDescription
indexesOrIdMaybeGetter<undefined | IndexesOrIndexesId>

The Indexes object, its Id, or a getter returning either.

indexIdMaybeGetter<string>

The Id of the index, or a getter returning it.

returns{ store: Store | undefined; tableId: Id | undefined; }

An object with store and tableId getter properties.

Example

This example passes a TinyBase object into a Svelte component and reads the reactive object's current property.

App.svelte
<svelte:options runes={true} />

<script>
  import {getIndexStoreTableId} from 'tinybase/ui-svelte';

  let {indexes} = $props();

  const result = getIndexStoreTableId(indexes, 'bySpecies');
</script>

{result.tableId}
import {flushSync, mount} from 'svelte';
import {createIndexes, createStore} from 'tinybase';
import App from './App.svelte';

const store = createStore()
  .setTables({
    pets: {
      fido: {species: 'dog', color: 'brown', sold: false, next: 'felix'},
      felix: {species: 'cat', color: 'black', sold: true},
    },
    species: {dog: {price: 5}, cat: {price: 4}},
  })
  .setValues({open: true, employees: 3});
const indexes = createIndexes(store).setIndexDefinition(
  'bySpecies',
  'pets',
  'species',
);
const app = document.body.appendChild(document.createElement('div'));
flushSync(() => mount(App, {target: app, props: {indexes}}));
console.log(app.textContent);
// -> 'pets'

Since

v8.1.0