TinyBase

setSchema

The setSchema method lets you specify the Schema of the Store.

setSchema(tablesSchema: Schema): Store
TypeDescription
tablesSchemaSchema
returnsStore

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 Schema with the delSchema method.

Example

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

const store = createStore().setSchema({
  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}}}