TinyBase logoTinyBase β

SelectAll

The SelectAll type describes a function that lets you select every Cell present in a source Row.

Calling this function with no parameters will select every Cell present in each Row of the query's root Table, retaining the source Cell Ids.

(): void

Example

This example selects all the Cells from heterogeneous root Rows:

import {createQueries, createStore} from 'tinybase';

const store = createStore().setTable('pets', {
  fido: {species: 'dog', color: 'brown'},
  felix: {species: 'cat', indoor: true},
});
const queries = createQueries(store);

queries.setQueryDefinition('query', 'pets', ({selectAll}) => selectAll());

console.log(queries.getResultRow('query', 'fido'));
// -> {color: 'brown', species: 'dog'}
console.log(queries.getResultRow('query', 'felix'));
// -> {indoor: true, species: 'cat'}

Since

v9.4.0


Calling this function with a joined Table Id will select every Cell present in the joined Row.

(
  joinedTableId: string,
  cellIdPrefixOrMapper?: string | CellIdMapper,
): void
TypeDescription
joinedTableIdstring

The Id of the joined Table. If the Table was joined 'as' a different Id, that should instead be used.

cellIdPrefixOrMapper?string | CellIdMapper

An optional prefix to prepend to every Cell Id, or a CellIdMapper callback that returns each result Cell Id.

returnsvoid

This has no return value.

An optional second parameter can map each Cell Id with a prefix or callback.

Example

This example selects all the Cells from a joined Table, retaining their Cell Ids:

import {createQueries, createStore} from 'tinybase';

const store = createStore()
  .setTable('pets', {fido: {ownerId: '1'}})
  .setTable('owners', {'1': {name: 'Alice', city: 'London'}});
const queries = createQueries(store);

queries.setQueryDefinition('query', 'pets', ({selectAll, join}) => {
  selectAll('owners');
  join('owners', 'ownerId');
});

console.log(queries.getResultRow('query', 'fido'));
// -> {city: 'London', name: 'Alice'}

Since

v9.4.0


Calling this function with true and a joined query Id will select every Cell present in the joined result Row.

(
  asQuery: true,
  joinedQueryId: string,
  cellIdPrefixOrMapper?: string | CellIdMapper,
): void
TypeDescription
asQuerytrue

A flag indicating that the next Id is a query Id.

joinedQueryIdstring

The Id of the joined query result. If the query result was joined 'as' a different Id, that should instead be used.

cellIdPrefixOrMapper?string | CellIdMapper

An optional prefix to prepend to every Cell Id, or a CellIdMapper callback that returns each result Cell Id.

returnsvoid

This has no return value.

An optional third parameter can map each Cell Id with a prefix or callback.

Example

This example selects all the Cells from a joined query result, prefixing each Cell Id:

import {createQueries, createStore} from 'tinybase';

const store = createStore()
  .setTable('pets', {fido: {ownerId: '1'}})
  .setTable('owners', {'1': {name: 'Alice', city: 'London'}});
const queries = createQueries(store)
  .setQueryDefinition('owners', 'owners', ({selectAll}) => selectAll())
  .setQueryDefinition('query', 'pets', ({selectAll, join}) => {
    selectAll(true, 'owners', 'owner.');
    join(true, 'owners', 'ownerId');
  });

console.log(queries.getResultRow('query', 'fido'));
// -> {'owner.city': 'London', 'owner.name': 'Alice'}

Since

v9.4.0

The SelectAll function is provided to the third query parameter of the setQueryDefinition method. Different source Rows can contain different Cell Ids, and each result Row will contain only the Cells present in its corresponding source Row. The result Table's Cell Ids are therefore the union of the Cells in its result Rows.

Source Cell Ids are processed in lexical order, and selection clauses are processed in the order they are declared. If multiple selected Cells map to the same result Cell Id, the later one wins.

When used in a grouped query, the current table-wide union of source Cell Ids is expanded into individual selections. The query is rebuilt if this union changes, and any selected Cell that is not grouped becomes a grouping dimension as usual.

A cycle between query results is allowed when every SelectAll clause retains its source Cell Ids. A prefix or CellIdMapper callback in such a cycle is rejected because it could expand Cell Ids indefinitely.

Since

v9.4.0