Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Update attachments README #451

Merged
merged 1 commit into from
Dec 19, 2024
Merged
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
42 changes: 20 additions & 22 deletions packages/attachments/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,20 @@ In this example, the user captures photos when checklist items are completed as
The schema for the `checklist` table:

```javascript
const AppSchema = new Schema([
new Table({
name: 'checklists',
columns: [
new Column({ name: 'photo_id', type: ColumnType.TEXT }),
new Column({ name: 'description', type: ColumnType.TEXT }),
new Column({ name: 'completed', type: ColumnType.INTEGER }),
new Column({ name: 'completed_at', type: ColumnType.TEXT }),
new Column({ name: 'completed_by', type: ColumnType.TEXT })
],
indexes: [
new Index({
name: 'inspections',
columns: [new IndexedColumn({ name: 'checklist_id' })]
})
]
})
]);
const checklists = new Table(
{
photo_id: column.text,
description: column.text,
completed: column.integer,
completed_at: column.text,
completed_by: column.text
},
{ indexes: { inspections: ['checklist_id'] } }
);

const AppSchema = new Schema({
checklists
});
```

### Steps to implement
Expand Down Expand Up @@ -107,10 +103,12 @@ export class AttachmentQueue extends AbstractAttachmentQueue {
```javascript
import { AttachmentTable } from '@powersync/attachments';

const AppSchema = new Schema([
const attachmentTable = new AttachmentTable();

const AppSchema = new Schema({
// ... other tables
new AttachmentTable()
]);
attachmentTable
});
```

In addition to `Table` options, the `AttachmentTable` can optionally be configured with the following options:
Expand All @@ -132,7 +130,7 @@ The default columns in `AttachmentTable`:
| `size` | `INTEGER` | The size of the attachment in bytes |

5. To instantiate an `AttachmentQueue`, one needs to provide an instance of `AbstractPowerSyncDatabase` from PowerSync and an instance of `StorageAdapter`.
See the `StorageAdapter` interface definition [here](./src/StorageAdapter.ts).
See the `StorageAdapter` interface definition [here](https://github.com/powersync-ja/powersync-js/blob/main/packages/attachments/src/StorageAdapter.ts).

6. Instantiate a new `AttachmentQueue` and call `init()` to start syncing attachments. Our example, uses a `StorageAdapter` that integrates with Supabase Storage.

Expand Down
Loading