TinyBase logoTinyBase β

createTools

The createTools function creates a Tools object, and is the main entry point into the tools module.

createTools(store: Store): Tools
TypeDescription
storeStore

The Store for which to register tools.

returnsTools

A reference to the new Tools object.

A given Store can only have one Tools object associated with it. If you call this function twice on the same Store, your second call will return a reference to the Tools object created by the first.

Examples

This example creates a Tools object.

import {createStore} from 'tinybase';
import {createTools} from 'tinybase/tools';

const store = createStore()
  .setTable('pets', {
    fido: {species: 'dog', color: 'brown'},
    felix: {species: 'cat', color: 'black'},
    cujo: {species: 'dog', color: 'black'},
  })
  .setTable('species', {
    dog: {price: 5},
    cat: {price: 4},
  })
  .setValues({open: true, employees: 3});
console.log(createTools(store).getStoreStats());
// -> {totalTables: 2, totalRows: 5, totalCells: 8, totalValues: 2, jsonLength: 212}

This example creates a Tools object, and calls the method a second time for the same Store to return the same object.

import {createStore} from 'tinybase';
import {createTools} from 'tinybase/tools';

const store = createStore();
const tools1 = createTools(store);
const tools2 = createTools(store);
console.log(tools1 === tools2);
// -> true

Since

v2.2.0