Skip to content

Commit 025088a

Browse files
committed
Extend Table instead of using createAttachmentTable function
1 parent 186bf4f commit 025088a

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

packages/powersync-attachments/src/AbstractAttachmentQueue.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
StorageAdapter,
99
AttachmentRecord,
1010
AttachmentState,
11-
createAttachmentTable,
1211
} from "./definitions";
1312

1413
export interface AttachmentQueueOptions {
@@ -46,9 +45,6 @@ export abstract class AbstractAttachmentQueue<
4645
this.uploading = false;
4746
this.downloading = false;
4847
this.initialSync = this.options.performInitialSync;
49-
50-
// Add Attachment table to schema tables
51-
this.powersync.schema.tables.push(createAttachmentTable());
5248
}
5349

5450
/**

packages/powersync-attachments/src/definitions/Schema.ts

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { Column, ColumnType, Table } from "@journeyapps/powersync-sdk-common";
1+
import {
2+
Column,
3+
ColumnType,
4+
Table,
5+
TableOptions,
6+
} from "@journeyapps/powersync-sdk-common";
27

38
export const ATTACHMENT_TABLE = "attachments";
49

@@ -20,16 +25,25 @@ export enum AttachmentState {
2025
ARCHIVED = 4, // Attachment has been orphaned, i.e. the associated record has been deleted
2126
}
2227

23-
export function createAttachmentTable(name: string = ATTACHMENT_TABLE) {
24-
return Table.createLocalOnly({
25-
name: name,
26-
columns: [
27-
new Column({ name: "filename", type: ColumnType.TEXT }),
28-
new Column({ name: "local_uri", type: ColumnType.TEXT }),
29-
new Column({ name: "timestamp", type: ColumnType.INTEGER }),
30-
new Column({ name: "size", type: ColumnType.INTEGER }),
31-
new Column({ name: "media_type", type: ColumnType.TEXT }),
32-
new Column({ name: "state", type: ColumnType.INTEGER }), // Corresponds to AttachmentState
33-
],
34-
});
28+
export interface AttachmentTableOptions extends Omit<TableOptions, "name"> {
29+
name?: string;
30+
additionalColumns?: Column[];
31+
}
32+
33+
export class AttachmentTable extends Table {
34+
constructor(options: AttachmentTableOptions) {
35+
super({
36+
...options,
37+
name: options.name ?? ATTACHMENT_TABLE,
38+
columns: [
39+
new Column({ name: "filename", type: ColumnType.TEXT }),
40+
new Column({ name: "local_uri", type: ColumnType.TEXT }),
41+
new Column({ name: "timestamp", type: ColumnType.INTEGER }),
42+
new Column({ name: "size", type: ColumnType.INTEGER }),
43+
new Column({ name: "media_type", type: ColumnType.TEXT }),
44+
new Column({ name: "state", type: ColumnType.INTEGER }), // Corresponds to AttachmentState
45+
...(options.additionalColumns ?? []),
46+
],
47+
});
48+
}
3549
}

0 commit comments

Comments
 (0)