TinyBase logoTinyBase

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.

import {createStore} from 'tinybase';

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

This example creates a Store with some initial data:

import {createStore} from 'tinybase';

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 TablesSchema:

import {createStore} from 'tinybase';

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

See also

The Basics guides

Since

v1.0.0