TinyBase logoTinyBase

DpcJson

The DpcJson type describes the configuration of a database-oriented Persister operating in serialized JSON mode.

{
  mode: "json";
  storeTableName?: string;
  autoLoadIntervalSeconds?: number;
}
TypeDescription
mode"json"

The mode to be used for persisting the Store to the database, in this case JSON serialization. See the DpcTabular type for the alternative tabular mapping mode.

storeTableName?string

An optional string which indicates the name of a table in the database which will be used to serialize the Store content into. It defaults to tinybase.

autoLoadIntervalSeconds?number

How often the Persister should poll the database for any changes made to it by other clients, defaulting to 1 second.

The only setting is the storeTableName property, which indicates the name of a table in the database which will be used to serialize the Store content into. It defaults to tinybase.

That table in the database will be given two columns: a primary key column called _id, and one called store. The Persister will place a single row in this table with _ in the _id column, and the JSON serialization in the store column, something like:

> SELECT * FROM tinybase;
+-----+-----------------------------------------------------+
| _id | store                                               |
+-----+-----------------------------------------------------+
| _   | [{"pets":{"fido":{"species":"dog"}}},{"open":true}] |
+-----+-----------------------------------------------------+

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 a JSON serialization from and to a table called tinybase_json.

const databasePersisterConfig: DatabasePersisterConfig = {
  mode: 'json',
  storeTableName: 'tinybase_json',
};

Since

v4.0.0