Skip to content

Commit 21dce42

Browse files
committed
chore: minor improvements to powersync-attachments readme
1 parent ffff573 commit 21dce42

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

packages/powersync-attachments/README.md

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ A [PowerSync](https://powersync.co) library to manage attachments in TypeScript
44

55
Note: This package is currently in a beta release.
66

7-
# Usage
87

98
## Installation
109

@@ -18,13 +17,13 @@ yarn add @journeyapps/powersync-attachments
1817
pnpm install @journeyapps/powersync-attachments
1918
```
2019

21-
## API
22-
23-
### Implement an `AttachmentQueue`
20+
## Usage
2421

2522
The `AttachmentQueue` class is used to manage and sync attachments in your app.
2623

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:
2827

2928
```typescript
3029
const AppSchema = new Schema([
@@ -47,10 +46,19 @@ const AppSchema = new Schema([
4746
]);
4847
```
4948

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`.
52+
```typescript
53+
import { AbstractAttachmentQueue } from '@journeyapps/powersync-attachments';
54+
55+
export class AttachmentQueue extends AbstractAttachmentQueue {
56+
57+
}
58+
```
59+
60+
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.
5462

5563
```typescript
5664
import { AbstractAttachmentQueue } from '@journeyapps/powersync-attachments';
@@ -67,7 +75,9 @@ export class AttachmentQueue extends AbstractAttachmentQueue {
6775
}
6876
```
6977

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.
7181

7282
```typescript
7383
import { AbstractAttachmentQueue } from '@journeyapps/powersync-attachments';
@@ -118,9 +128,10 @@ The default columns in the `AttachmentTable` are:
118128
| `timestamp` | `INTEGER` | The timestamp of last update to the attachment record |
119129
| `size` | `INTEGER` | The size of the attachment in bytes |
120130

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).
122133

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
124135

125136
```typescript
126137
this.storage = this.supabaseConnector.storage;

0 commit comments

Comments
 (0)