DpcTabular
The DpcTabular
type describes the configuration of a database-oriented Persister
that is operating in tabular mapping mode.
{
mode: "tabular";
tables?: {
load?: DpcTabularLoad;
save?: DpcTabularSave;
};
values?: DpcTabularValues;
autoLoadIntervalSeconds?: number;
}
Type | Description | |
---|---|---|
mode | "tabular" | The mode to be used for persisting the |
tables? | { load?: DpcTabularLoad; save?: DpcTabularSave; } | The settings for how the |
values? | DpcTabularValues | The settings for how the |
autoLoadIntervalSeconds? | number | How often the |
It is important to note that both the tabular mapping in ('save') and out ('load') of an underlying database are disabled by default. This is to ensure that if you pass in an existing populated database you don't run the immediate risk of corrupting or losing all your data.
This configuration therefore takes a tables
property object (with child load
and save
property objects) and a values
property object. These indicate how you want to load and save Tables
and Values
respectively. At least one of these two properties are required for the Persister
to do anything!
Note that if you are planning to both load from and save to a database, it is important to make sure that the load and save table mappings are symmetrical. For example:
const databasePersisterConfig: DatabasePersisterConfig = {
mode: 'tabular',
tables: {
load: {petsInDb: 'pets', speciesInDb: 'species'},
save: {pets: 'petsInDb', species: 'speciesInDb'},
},
};
See the documentation for the DpcTabularLoad
, DpcTabularSave
, and DpcTabularValues
types for more details on how to configure the tabular mapping mode.
The 'Dpc' prefix indicates that this type is used within the DatabasePersisterConfig
type.
Example
When applied to a database Persister
, this DatabasePersisterConfig
will load and save Tables
data from and to tables specified in the load
and save
mappings, and Values
data from and to a table called my_tinybase_values
.
const databasePersisterConfig: DatabasePersisterConfig = {
mode: 'tabular',
tables: {
load: {petsInDb: 'pets', speciesInDb: 'species'},
save: {pets: 'petsInDb', species: 'speciesInDb'},
},
values: {
load: true,
save: true,
tableName: 'my_tinybase_values',
},
};
Since
v4.0.0