TinyBase logoTinyBase β

setTable

The setTable method takes an object and sets the entire data of a single Table in the Store.

setTable(
  tableId: string,
  table: Table,
): this
TypeDescription
tableIdstring

The Id of the Table in the Store.

tableTable

The data of a single Table to be set.

returnsthis

A reference to the Store.

This method will cause listeners to be called for any Table, Row, Cell, or Id changes resulting from it.

Any part of the provided object that is invalid (either according to the Table type, or because it does not match a TablesSchema associated with the Store), will be ignored silently.

Assuming that at least some of the provided Table object is valid, any data that was already present in the Store for that Table will be completely overwritten. If the object is completely invalid, no change will be made to the Store.

The method returns a reference to the Store so that subsequent operations can be chained in a fluent style.

Examples

This example sets the data of a single Table.

import {createStore} from 'tinybase';

const store = createStore().setTable('pets', {
  fido: {species: 'dog'},
  felix: {species: 'cat'},
});
console.log(store.getTables());
// -> {pets: {fido: {species: 'dog'}, felix: {species: 'cat'}}}

This example attempts to set the data of an existing Store with partly invalid, and then completely invalid, Table objects.

import {createStore} from 'tinybase';

const store = createStore().setTables({pets: {fido: {species: 'dog'}}});

store.setTable('pets', {felix: {species: 'cat', bug: []}});
console.log(store.getTables());
// -> {pets: {felix: {species: 'cat'}}}

store.setTable('pets', {meaning: 42});
console.log(store.getTables());
// -> {pets: {felix: {species: 'cat'}}}

Since

v1.0.0