You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `AttachmentQueue` class is used to manage and sync attachments in your app.
26
23
27
-
In this example we are capturing photos as part of an inspection workflow. Here is the schema for the `checklist` table:
24
+
In this example we are capturing photos as part of an inspection workflow.
25
+
26
+
Here is the schema for the `checklist` table:
28
27
29
28
```typescript
30
29
const AppSchema =newSchema([
@@ -47,10 +46,19 @@ const AppSchema = new Schema([
47
46
]);
48
47
```
49
48
50
-
1. Implement a new class `AttachmentQueue` that extends `AbstractAttachmentQueue` from `@journeyapps/powersync-attachments`.
51
-
2. Implement the `attachmentIds` AsyncIterator method to return an array of `string` values of IDs that relate to attachments in your app.
52
-
53
-
We use `PowerSync`'s watch query to return the all IDs of photos that have been captured as part of an inspection, and map them to an array of `string` values.
49
+
### Steps to implement `AttachmentQueue`
50
+
51
+
1. Create a new class `AttachmentQueue` that extends `AbstractAttachmentQueue` from `@journeyapps/powersync-attachments`.
2. Implement `attachmentIds`, an `AsyncIterator` method to return an array of `string` values of IDs that relate to attachments in your app. We recommend using `PowerSync`'s `watch` query to return the all IDs of attachments in your app.
61
+
In this example, we query all photos that have been captured as part of an inspection and map them to an array of `string` values.
@@ -67,7 +75,9 @@ export class AttachmentQueue extends AbstractAttachmentQueue {
67
75
}
68
76
```
69
77
70
-
3. Implement `newAttachmentRecord` to return an object that represents the attachment record in your app. In this example we always work with JPEG images, but you can use any media type that is supported by your app and storage solution.
78
+
3. Implement `newAttachmentRecord` to return an object that represents the attachment record in your app.
79
+
In this example we always work with `JPEG` images, but you can use any media type that is supported by your app and storage solution.
80
+
Note in this example we are setting the state to `QUEUED_UPLOAD` when creating a new photo record which assumes that the photo data is already on the device.
@@ -118,9 +128,10 @@ The default columns in the `AttachmentTable` are:
118
128
|`timestamp`|`INTEGER`| The timestamp of last update to the attachment record |
119
129
|`size`|`INTEGER`| The size of the attachment in bytes |
120
130
121
-
5. To instantiate an `AttachmentQueue`, one needs to provide an instance of `AbstractPowerSyncDatabase` from PowerSync and an instance of `StorageAdapter`. For the specifications about what must be implemented in `StorageAdapter`, please refer to its interface definition.
131
+
5. To instantiate an `AttachmentQueue`, one needs to provide an instance of `AbstractPowerSyncDatabase` from PowerSync and an instance of `StorageAdapter`.
132
+
See the `StorageAdapter` interface definition [here](./src/StorageAdapter.ts).
122
133
123
-
6.Instantiate you `AttachmentQueue` and call `init()` to start syncing attachments. (Example below uses Supabase Storage)
134
+
6.Finally, create a new `AttachmentQueue` and call `init()` to start syncing attachments. Our example, uses a `StorageAdapter` that integrates with Supabase Storage
0 commit comments