TinyBase

delCell

The delCell method lets you remove a single Cell from a Row.

delCell(
  tableId: string,
  rowId: string,
  cellId: string,
  forceDel?: boolean,
): Store
TypeDescription
tableIdstring

The Id of the Table in the Store.

rowIdstring

The Id of the Row in the Table.

cellIdstring

The Id of the Cell in the Row.

forceDel?boolean

An optional flag to indicate that the whole Row should be deleted, even if a Schema provides a default value for this Cell. Defaults to false.

returnsStore

A reference to the Store.

When there is no Schema applied to the Store, then if this is the last Cell in its Row, then that Row will be removed. If, in turn, that is the last Row in its Table, then that Table will be removed.

If there is a Schema applied to the Store and it specifies a default value for this Cell, then deletion will result in it being set back to its default value. To override this, use the forceDel parameter, as described below.

The forceDel parameter is an optional flag that is only relevant if a Schema provides a default value for this Cell. Under such circumstances, deleting a Cell value will normally restore it to the default value. If this flag is set to true, the complete removal of the Cell is instead guaranteed. But since doing do so would result in an invalid Row (according to the Schema), in fact the whole Row is deleted to retain the integrity of the Table. Therefore, this flag should be used with caution.

Examples

This example removes a Cell from a Row without a Schema.

const store = createStore().setTables({
  pets: {fido: {species: 'dog', sold: true}},
});
store.delCell('pets', 'fido', 'sold');

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

This example removes a Cell from a Row with a Schema that defaults its value.

const store = createStore()
  .setTables({
    pets: {fido: {species: 'dog', sold: true}},
  })
  .setSchema({
    pets: {
      species: {type: 'string'},
      sold: {type: 'boolean', default: false},
    },
  });
store.delCell('pets', 'fido', 'sold');

console.log(store.getTables());
// -> {pets: {fido: {species: 'dog', sold: false}}}

This example removes a Cell from a Row with a Schema that defaults its value, but uses the forceDel parameter to override it.

const store = createStore()
  .setTables({
    pets: {fido: {species: 'dog', sold: true}, felix: {species: 'cat'}},
  })
  .setSchema({
    pets: {
      species: {type: 'string'},
      sold: {type: 'boolean', default: false},
    },
  });
store.delCell('pets', 'fido', 'sold', true);

console.log(store.getTables());
// -> {pets: {felix: {species: 'cat', sold: false}}}