Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .changeset/clean-poems-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
'@powersync/attachments': major
'@powersync/react-native': major
'@powersync/common': major
'@powersync/web': major
'@powersync/capacitor': minor
'@powersync/node': minor
'@powersync/nuxt': minor
---

Remove the deprecated table v1 syntax. To create tables based on column arrays, use the new ResolvedTable class.
49 changes: 21 additions & 28 deletions demos/angular-supabase-todolist/src/app/powersync.service.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { Injectable } from '@angular/core';
import {
AbstractPowerSyncDatabase,
Column,
ColumnType,
column,
CommonPowerSyncDatabase,
createConsoleLogger,
Index,
IndexedColumn,
LogLevels,
PowerSyncBackendConnector,
PowerSyncDatabase,
Expand Down Expand Up @@ -36,35 +33,31 @@ export interface TodoRecord {
export const LISTS_TABLE = 'lists';
export const TODOS_TABLE = 'todos';

export const AppSchema = new Schema([
new Table({
name: TODOS_TABLE,
columns: [
new Column({ name: 'list_id', type: ColumnType.TEXT }),
new Column({ name: 'created_at', type: ColumnType.TEXT }),
new Column({ name: 'completed_at', type: ColumnType.TEXT }),
new Column({ name: 'description', type: ColumnType.TEXT }),
new Column({ name: 'completed', type: ColumnType.INTEGER }),
new Column({ name: 'created_by', type: ColumnType.TEXT }),
new Column({ name: 'completed_by', type: ColumnType.TEXT })
],
indexes: [new Index({ name: 'list', columns: [new IndexedColumn({ name: 'list_id' })] })]
}),
new Table({
name: LISTS_TABLE,
columns: [
new Column({ name: 'created_at', type: ColumnType.TEXT }),
new Column({ name: 'name', type: ColumnType.TEXT }),
new Column({ name: 'owner_id', type: ColumnType.TEXT })
]
export const AppSchema = new Schema({
[TODOS_TABLE]: new Table(
{
list_id: column.text,
created_at: column.text,
completed_at: column.text,
description: column.text,
completed: column.integer,
created_by: column.text,
completed_by: column.text
},
{ indexes: { list: ['list_id'] } }
),
[LISTS_TABLE]: new Table({
created_at: column.text,
name: column.text,
owner_id: column.text
})
]);
});

@Injectable({
providedIn: 'root'
})
export class PowerSyncService {
db: AbstractPowerSyncDatabase;
db: CommonPowerSyncDatabase;

constructor() {
const factory = new WASQLiteOpenFactory({
Expand Down
39 changes: 17 additions & 22 deletions demos/react-multi-client/src/definitions/Schema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Column, ColumnType, Schema, Table } from '@powersync/web';
import { column, Schema, Table } from '@powersync/web';

export const TABLE_NAME = 'pebbles';
export const MAX_PEBBLES = 5;
Expand All @@ -19,29 +19,24 @@ export interface PebbleDef {
user_id: string;
}

export const AppSchema = new Schema([
new Table({
name: TABLE_NAME,
columns: [
new Column({ name: 'shape', type: ColumnType.TEXT }),
new Column({ name: 'created_at', type: ColumnType.TEXT }),
new Column({ name: 'user_id', type: ColumnType.TEXT })
]
export const AppSchema = new Schema({
[TABLE_NAME]: new Table({
shape: column.text,
created_at: column.text,
user_id: column.text
}),
new Table({
name: 'operations',
columns: [
new Column({ name: 'operation', type: ColumnType.TEXT }),
new Column({ name: 'created_at', type: ColumnType.TEXT }),
new Column({ name: 'user_id', type: ColumnType.TEXT })
]
operations: new Table({
operation: column.text,
created_at: column.text,
user_id: column.text
}),
new Table({
name: 'settings',
localOnly: true,
columns: [new Column({ name: 'initialized', type: ColumnType.INTEGER })]
})
]);
settings: new Table(
{
initialized: column.integer
},
{ localOnly: true }
)
});

export function randomPebbleShape(): Shape {
const colors = Object.values(Shape);
Expand Down
38 changes: 21 additions & 17 deletions packages/attachments/src/Schema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Column, ColumnType, Table, TableOptions } from '@powersync/common';
import { ColumnsType, Table, column, TableOptions } from '@powersync/common';

export const ATTACHMENT_TABLE = 'attachments';

Expand All @@ -22,25 +22,29 @@ export enum AttachmentState {

export interface AttachmentTableOptions extends Omit<TableOptions, 'name' | 'columns'> {
name?: string;
additionalColumns?: Column[];
additionalColumns?: ColumnsType;
}

export class AttachmentTable extends Table {
constructor(options?: AttachmentTableOptions) {
super({
...options,
name: options?.name ?? ATTACHMENT_TABLE,
localOnly: true,
insertOnly: false,
columns: [
new Column({ name: 'filename', type: ColumnType.TEXT }),
new Column({ name: 'local_uri', type: ColumnType.TEXT }),
new Column({ name: 'timestamp', type: ColumnType.INTEGER }),
new Column({ name: 'size', type: ColumnType.INTEGER }),
new Column({ name: 'media_type', type: ColumnType.TEXT }),
new Column({ name: 'state', type: ColumnType.INTEGER }), // Corresponds to AttachmentState
...(options?.additionalColumns ?? [])
]
});
const { additionalColumns = {}, ...tableOptions } = options ?? {};

super(
{
filename: column.text,
local_uri: column.text,
timestamp: column.integer,
size: column.integer,
media_type: column.text,
state: column.integer,
...additionalColumns
},
{
name: ATTACHMENT_TABLE,
...tableOptions,
localOnly: true,
insertOnly: false
}
);
}
}
Loading
Loading