TinyBase logoTinyBase

DpcTabularLoad

The DpcTabularLoad type describes the configuration for loading Tables in a database-oriented Persister that is operating in tabular mode.

{[tableName: string]: {
  tableId: Id;
  rowIdColumnName?: string;
} | Id}

It is an object where each key is a name of a database table, and the value is a child configuration object for how that table should be loaded into the Store. The properties of the child configuration object are:

TypeDescription
tableIdIdThe Id of the Store Table into which data from this database table should be loaded.
rowIdColumnName?stringThe optional name of the column in the database table that will be used as the Row Ids in the Store Table, defaulting to '_id'.

As a shortcut, if you do not need to specify a custom rowIdColumnName, you can simply provide the Id of the Store Table instead of the whole object.

The 'Dpc' prefix indicates that this type is used within the DatabasePersisterConfig type.

Example

When applied to a database Persister, this DatabasePersisterConfig will load the data of two database tables (called 'petsInDb' and 'speciesInDb') into two Store Tables (called 'pets' and 'species'). One has a column for the Row Id called 'id' and the other defaults it to '_id'.

const databasePersisterConfig: DatabasePersisterConfig = {
  mode: 'tabular',
  tables: {
    load: {
      petsInDb: {tableId: 'pets', rowIdColumnName: 'id'},
      speciesInDb: 'species',
    },
  },
};

Imagine database tables that look like this:

> SELECT * FROM petsInDb;
+-------+---------+-------+
| id    | species | color |
+-------+---------+-------+
| fido  | dog     | brown |
| felix | cat     | black |
+-------+---------+-------+

> SELECT * FROM speciesInDb;
+------+-------+
| _id  | price |
+------+-------+
| dog  | 5     |
| cat  | 4     |
+------+-------+

With the configuration above, this will load into a Store with Tables that look like this:

{
  "pets": {
    "fido": {"species": "dog", "color": "brown"},
    "felix": {"species": "cat", "color": "black"},
  },
  "species": {
    "dog": {"price": 5},
    "cat": {"price": 4},
  },
}

Since

v4.0.0