TinyBase logoTinyBase β

setTablesSchema

The setTablesSchema method lets you specify the TablesSchema of the tabular part of the Store.

setTablesSchema(tablesSchema: TablesSchema): this
TypeDescription
tablesSchemaTablesSchema

The TablesSchema to be set for the Store.

returnsthis

A reference to the Store.

Note that this may result in a change to data in the Store, as defaults are applied or as invalid Table, Row, or Cell objects are removed. These changes will fire any listeners to that data, as expected.

When no longer needed, you can also completely remove an existing TablesSchema with the delTablesSchema method.

Example

This example sets the TablesSchema of a Store after it has been created.

import {createStore} from 'tinybase';

const store = createStore().setTablesSchema({
  pets: {
    species: {type: 'string'},
    sold: {type: 'boolean', default: false},
  },
});
store.addRow('pets', {species: 'dog', color: 'brown', sold: 'maybe'});

console.log(store.getTables());
// -> {pets: {0: {species: 'dog', sold: false}}}

Since

v3.0.0