TinyBase logoTinyBase

DpcJson

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

{
  mode: "json";
  storeTableName?: string;
  storeIdColumnName?: string;
  storeColumnName?: 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.

storeIdColumnName?string

The optional name of the column in the database table that will be used as the Id for the Store, defaulting to '_id', since v5.0.

storeColumnName?string

The optional name of the column in the database table that will be used for the JSON of the Store, defaulting to 'store', since v5.0.

autoLoadIntervalSeconds?number

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

One 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. (These column names can be changed using the rowIdColumnName and storeColumnName settings). 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 the following.

> 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.

import type {DatabasePersisterConfig} from 'tinybase';

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

Since

v4.0.0