Skip to content

Commit dd4474d

Browse files
chore: clean up attachments readme and update demos (#453)
1 parent a9d1954 commit dd4474d

File tree

5 files changed

+671
-209
lines changed

5 files changed

+671
-209
lines changed
Lines changed: 32 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,40 @@
11
import { AttachmentTable } from '@powersync/attachments';
2-
import { Column, ColumnType, Index, IndexedColumn, Schema, Table } from '@powersync/react-native';
2+
import { column, Schema, Table } from '@powersync/react-native';
33

4-
export const TODO_TABLE = 'todos';
54
export const LIST_TABLE = 'lists';
5+
export const TODO_TABLE = 'todos';
66

7-
export interface ListRecord {
8-
id: string;
9-
name: string;
10-
created_at: string;
11-
owner_id?: string;
12-
}
7+
const todos = new Table(
8+
{
9+
list_id: column.text,
10+
photo_id: column.text,
11+
created_at: column.text,
12+
completed_at: column.text,
13+
description: column.text,
14+
created_by: column.text,
15+
completed_by: column.text,
16+
completed: column.integer
17+
},
18+
{ indexes: { list: ['list_id'] } }
19+
);
1320

14-
export interface TodoRecord {
15-
id: string;
16-
created_at: string;
17-
completed: boolean;
18-
description: string;
19-
completed_at?: string;
21+
const lists = new Table({
22+
created_at: column.text,
23+
name: column.text,
24+
owner_id: column.text
25+
});
2026

21-
created_by: string;
22-
completed_by?: string;
23-
list_id: string;
27+
export const AppSchema = new Schema({
28+
todos,
29+
lists,
30+
attachments: new AttachmentTable({
31+
name: 'attachments',
32+
}),
33+
});
2434

25-
photo_id?: string; // This is the attachment id, 1:1 relationship with `id` in AttachmentTable
26-
}
35+
export type Database = (typeof AppSchema)['types'];
36+
export type TodoRecord = Database['todos'];
37+
// OR:
38+
// export type Todo = RowType<typeof todos>;
2739

28-
export const AppSchema = new Schema([
29-
new Table({
30-
name: 'todos',
31-
columns: [
32-
new Column({ name: 'list_id', type: ColumnType.TEXT }),
33-
new Column({ name: 'photo_id', type: ColumnType.TEXT }),
34-
new Column({ name: 'created_at', type: ColumnType.TEXT }),
35-
new Column({ name: 'completed_at', type: ColumnType.TEXT }),
36-
new Column({ name: 'description', type: ColumnType.TEXT }),
37-
new Column({ name: 'completed', type: ColumnType.INTEGER }),
38-
new Column({ name: 'created_by', type: ColumnType.TEXT }),
39-
new Column({ name: 'completed_by', type: ColumnType.TEXT })
40-
],
41-
indexes: [
42-
new Index({
43-
name: 'list',
44-
columns: [new IndexedColumn({ name: 'list_id' })]
45-
})
46-
]
47-
}),
48-
new Table({
49-
name: 'lists',
50-
columns: [
51-
new Column({ name: 'created_at', type: ColumnType.TEXT }),
52-
new Column({ name: 'name', type: ColumnType.TEXT }),
53-
new Column({ name: 'owner_id', type: ColumnType.TEXT })
54-
]
55-
}),
56-
// Add Attachment table
57-
new AttachmentTable()
58-
]);
40+
export type ListRecord = Database['lists'];
Lines changed: 32 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,40 @@
11
import { AttachmentTable } from '@powersync/attachments';
2-
import { Column, ColumnType, Index, IndexedColumn, Schema, Table } from '@powersync/common';
2+
import { column, Schema, Table } from '@powersync/react-native';
33

4-
export const TODO_TABLE = 'todos';
54
export const LIST_TABLE = 'lists';
5+
export const TODO_TABLE = 'todos';
66

7-
export interface ListRecord {
8-
id: string;
9-
name: string;
10-
created_at: string;
11-
owner_id?: string;
12-
}
7+
const todos = new Table(
8+
{
9+
list_id: column.text,
10+
photo_id: column.text,
11+
created_at: column.text,
12+
completed_at: column.text,
13+
description: column.text,
14+
created_by: column.text,
15+
completed_by: column.text,
16+
completed: column.integer
17+
},
18+
{ indexes: { list: ['list_id'] } }
19+
);
1320

14-
export interface TodoRecord {
15-
id: string;
16-
created_at: string;
17-
completed: boolean;
18-
description: string;
19-
completed_at?: string;
21+
const lists = new Table({
22+
created_at: column.text,
23+
name: column.text,
24+
owner_id: column.text
25+
});
2026

21-
created_by: string;
22-
completed_by?: string;
23-
list_id: string;
27+
export const AppSchema = new Schema({
28+
todos,
29+
lists,
30+
attachments: new AttachmentTable({
31+
name: 'attachments',
32+
}),
33+
});
2434

25-
photo_id?: string; // This is the attachment id, 1:1 relationship with `id` in AttachmentTable
26-
}
35+
export type Database = (typeof AppSchema)['types'];
36+
export type TodoRecord = Database['todos'];
37+
// OR:
38+
// export type Todo = RowType<typeof todos>;
2739

28-
export const AppSchema = new Schema([
29-
new Table({
30-
name: 'todos',
31-
columns: [
32-
new Column({ name: 'list_id', type: ColumnType.TEXT }),
33-
new Column({ name: 'photo_id', type: ColumnType.TEXT }),
34-
new Column({ name: 'created_at', type: ColumnType.TEXT }),
35-
new Column({ name: 'completed_at', type: ColumnType.TEXT }),
36-
new Column({ name: 'description', type: ColumnType.TEXT }),
37-
new Column({ name: 'completed', type: ColumnType.INTEGER }),
38-
new Column({ name: 'created_by', type: ColumnType.TEXT }),
39-
new Column({ name: 'completed_by', type: ColumnType.TEXT })
40-
],
41-
indexes: [
42-
new Index({
43-
name: 'list',
44-
columns: [new IndexedColumn({ name: 'list_id' })]
45-
})
46-
]
47-
}),
48-
new Table({
49-
name: 'lists',
50-
columns: [
51-
new Column({ name: 'created_at', type: ColumnType.TEXT }),
52-
new Column({ name: 'name', type: ColumnType.TEXT }),
53-
new Column({ name: 'owner_id', type: ColumnType.TEXT })
54-
]
55-
}),
56-
// Add Attachment table
57-
new AttachmentTable()
58-
]);
40+
export type ListRecord = Database['lists'];

packages/attachments/README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,11 @@ export class AttachmentQueue extends AbstractAttachmentQueue {
103103
```javascript
104104
import { AttachmentTable } from '@powersync/attachments';
105105

106-
const attachmentTable = new AttachmentTable();
107-
108106
const AppSchema = new Schema({
109107
// ... other tables
110-
attachmentTable
108+
attachments: new AttachmentTable({
109+
name: 'attachments',
110+
}),
111111
});
112112
```
113113
@@ -123,7 +123,7 @@ The default columns in `AttachmentTable`:
123123
| Column Name | Type | Description |
124124
| ------------ | --------- | ----------------------------------------------------------------- |
125125
| `id` | `TEXT` | The ID of the attachment record |
126-
| `filename` | `TEXT` | The filename of the attachment |
126+
| `filename` | `TEXT` | The filename of the attachment |
127127
| `media_type` | `TEXT` | The media type of the attachment |
128128
| `state` | `INTEGER` | The state of the attachment, one of `AttachmentState` enum values |
129129
| `timestamp` | `INTEGER` | The timestamp of last update to the attachment record |
@@ -136,7 +136,12 @@ The default columns in `AttachmentTable`:
136136
137137
```javascript
138138
this.storage = this.supabaseConnector.storage;
139-
this.powersync = factory.getInstance();
139+
this.powersync = new PowerSyncDatabase({
140+
schema: AppSchema,
141+
database: {
142+
dbFilename: 'sqlite.db'
143+
}
144+
});
140145

141146
this.attachmentQueue = new AttachmentQueue({
142147
powersync: this.powersync,

packages/attachments/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@
3333
},
3434
"devDependencies": {
3535
"@types/node": "^20.17.6",
36-
"@vitest/browser": "^2.1.4",
36+
"@vitest/browser": "^2.1.8",
3737
"ts-loader": "^9.5.1",
3838
"ts-node": "^10.9.2",
39-
"typescript": "^5.6.3",
40-
"vite": "^5.4.10",
39+
"typescript": "^5.7.2",
40+
"vite": "^5.4.11",
4141
"vite-plugin-top-level-await": "^1.4.4",
42-
"vitest": "^2.1.4",
43-
"webdriverio": "^9.2.8"
42+
"vitest": "^2.1.8",
43+
"webdriverio": "^9.4.5"
4444
}
4545
}

0 commit comments

Comments
 (0)