setSchema
The setSchema
method lets you specify the Schema
of the Store
.
setSchema(schema: Schema): 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.
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}}}