Schema<S>
A schema is a collection of tables. It is used to define the structure of a database.
Type Parameters
| Type Parameter | Default type |
|---|---|
S extends SchemaType | SchemaType |
Constructors
new Schema()
new Schema<S>(tables): Schema<S>
Parameters
| Parameter | Type |
|---|---|
tables | S | Table<ColumnsType>[] |
Returns
Schema<S>
Properties
| Property | Modifier | Type |
|---|---|---|
props | readonly | S |
rawTables | readonly | RawTable[] |
tables | readonly | Table<ColumnsType>[] |
types | readonly | SchemaTableType<S> |
Methods
toJSON()
toJSON(): {
raw_tables: unknown[];
tables: {
columns: {
name: string;
type: undefined | ColumnType;
}[];
ignore_empty_update: undefined | boolean;
include_metadata: undefined | boolean;
include_old: any;
include_old_only_when_changed: boolean;
indexes: {
columns: {
ascending: undefined | boolean;
name: string;
type: ColumnType;
}[];
name: string;
}[];
insert_only: undefined | boolean;
local_only: undefined | boolean;
name: string;
view_name: string;
}[];
}
Returns
{
raw_tables: unknown[];
tables: {
columns: {
name: string;
type: undefined | ColumnType;
}[];
ignore_empty_update: undefined | boolean;
include_metadata: undefined | boolean;
include_old: any;
include_old_only_when_changed: boolean;
indexes: {
columns: {
ascending: undefined | boolean;
name: string;
type: ColumnType;
}[];
name: string;
}[];
insert_only: undefined | boolean;
local_only: undefined | boolean;
name: string;
view_name: string;
}[];
}
| Name | Type |
|---|---|
raw_tables | unknown[] |
tables | { columns: { name: string; type: undefined | ColumnType; }[]; ignore_empty_update: undefined | boolean; include_metadata: undefined | boolean; include_old: any; include_old_only_when_changed: boolean; indexes: { columns: { ascending: undefined | boolean; name: string; type: ColumnType; }[]; name: string; }[]; insert_only: undefined | boolean; local_only: undefined | boolean; name: string; view_name: string; }[] |
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
| Parameter | Type | Description |
|---|---|---|
tables | Record<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
| Parameter | Type |
|---|---|
table | RawTable |
Returns
unknown