Skip to main content

Schema<S>

A schema is a collection of tables. It is used to define the structure of a database.

Type Parameters​

Type ParameterDefault type
S extends SchemaTypeSchemaType

Constructors​

Constructor​

new Schema<S>(tables): Schema<S>;

Parameters​

ParameterType
tablesS | ResolvedTable[]

Returns​

Schema<S>

Properties​

PropertyModifierType
propsreadonlyS
rawTablesreadonlyRawTable[]
tablesreadonlyResolvedTable[]
typesreadonlySchemaTableType<S>

Methods​

toJSON()​

toJSON(): unknown;

Returns​

unknown


validate()​

validate(): void;

Returns​

void


withRawTables()​

withRawTables(tables): void;

Adds raw tables to this schema. Raw tables are identified by their name, but entirely managed by the application developer instead of automatically by PowerSync. Since raw tables are not backed by JSON, running complex queries on them may be more efficient. Further, they allow using client-side table and column constraints.

Parameters​

ParameterTypeDescription
tablesRecord<string, RawTableType>An object of (table name, raw table definition) entries.

Returns​

void


rawTableToJson()​

static rawTableToJson(table): unknown;

Returns a representation of the raw table that is understood by the PowerSync SQLite core extension.

The output of this can be passed through JSON.serialize and then used in powersync_create_raw_table_crud_trigger to define triggers for this table.

Parameters​

ParameterType
tableRawTable

Returns​

unknown