Skip to content

Commit

Permalink
Fix: Update attachments README (#451)
Browse files Browse the repository at this point in the history
  • Loading branch information
mugikhan authored Dec 19, 2024
1 parent 4a262cd commit a9d1954
Showing 1 changed file with 20 additions and 22 deletions.
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

0 comments on commit a9d1954

Please sign in to comment.