TinyBase

createStore

The createStore function creates a Store, and is the main entry point into the store module.

createStore(): Store
returnsStore

A reference to the new Store.

Since (or perhaps because) it is the most important function in the whole module, it is trivially simple.

Examples

This example creates a Store.

const store = createStore();
console.log(store.getTables());
// -> {}

This example creates a Store with some initial data:

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

This example creates a Store with some initial data and a Schema:

const store = createStore()
  .setTables({pets: {fido: {species: 'dog'}}})
  .setSchema({
    pets: {
      species: {type: 'string'},
      sold: {type: 'boolean', default: false},
    },
  });
console.log(store.getTables());
// -> {pets: {fido: {species: 'dog', sold: false}}}

See also

The Basics guides