TinyBase logoTinyBase β

getTransactionLog

The getTransactionLog method returns the changes that were made to a Store during a transaction in more detail, including invalid changes, and what previous values were.

getTransactionLog(): TransactionLog
returnsTransactionLog

A TransactionLog object representing the changes.

This is useful for deciding whether to rollback a transaction, for example. The returned object is only meaningful if the method is called when the Store is in a transaction - such as in a TransactionListener.

Example

This example makes changes to the Store. At the end of the transaction, detail about what changed is enumerated.

import {createStore} from 'tinybase';

const store = createStore()
  .setTables({pets: {fido: {species: 'dog', color: 'brown'}}})
  .setValues({open: true});

store
  .startTransaction()
  .setCell('pets', 'fido', 'color', 'black')
  .setCell('pets', 'fido', 'date0', new Date(0))
  .setCell('pets', 'fido', 'date1', new Date(1))
  .setValue('open', false)
  .setValue('date2', new Date(2))
  .finishTransaction(() => {
    const [, , changedCells, invalidCells, changedValues, invalidValues] =
      store.getTransactionLog();
    console.log(changedCells);
    console.log(invalidCells);
    console.log(changedValues);
    console.log(invalidValues);
  });
// -> {pets: {fido: {color: ['brown', 'black']}}}
// -> {pets: {fido: {date0: [new Date(0)], date1: [new Date(1)]}}}
// -> {open: [true, false]}
// -> {date2: [new Date(2)]}

Since

v5.0.0