abstract
AbstractAttachmentQueue<T>
Type Parameters
Type Parameter | Default type |
---|---|
T extends AttachmentQueueOptions | AttachmentQueueOptions |
Constructors
new AbstractAttachmentQueue()
new AbstractAttachmentQueue<T>(options): AbstractAttachmentQueue<T>
Parameters
Parameter | Type |
---|---|
options | T |
Returns
Properties
Property | Type |
---|---|
downloading | boolean |
downloadQueue | Set <string > |
initialSync | boolean |
options | T |
uploading | boolean |
Accessors
storageDirectory
Get Signature
get storageDirectory(): string
Returns the directory where attachments are stored on the device, used to make dir Example: "/var/mobile/Containers/Data/Application/.../Library/attachments/"
Returns
string
table
Get Signature
get table(): string
Returns
string
Methods
clearQueue()
clearQueue(): Promise<void>
Returns
Promise
<void
>
delete()
delete(record, tx?): Promise<void>
Parameters
Parameter | Type |
---|---|
record | AttachmentRecord |
tx ? | Transaction |
Returns
Promise
<void
>
downloadRecord()
downloadRecord(record): Promise<boolean>
Parameters
Parameter | Type |
---|---|
record | AttachmentRecord |
Returns
Promise
<boolean
>
expireCache()
expireCache(): Promise<void>
Returns
Promise
<void
>
getIdsToDownload()
getIdsToDownload(): Promise<string[]>
Returns
Promise
<string
[]>
getLocalFilePathSuffix()
getLocalFilePathSuffix(filename): string
Returns the local file path for the given filename, used to store in the database. Example: filename: "attachment-1.jpg" returns "attachments/attachment-1.jpg"
Parameters
Parameter | Type |
---|---|
filename | string |
Returns
string
getLocalUri()
getLocalUri(filePath): string
Return users storage directory with the attachmentPath use to load the file. Example: filePath: "attachments/attachment-1.jpg" returns "/var/mobile/Containers/Data/Application/.../Library/attachments/attachment-1.jpg"
Parameters
Parameter | Type |
---|---|
filePath | string |
Returns
string
getNextUploadRecord()
getNextUploadRecord(): Promise<AttachmentRecord>
Returns
Promise
<AttachmentRecord
>
idsToDownload()
idsToDownload(onResult): void
Parameters
Parameter | Type |
---|---|
onResult | (ids ) => void |
Returns
void
idsToUpload()
idsToUpload(onResult): void
Parameters
Parameter | Type |
---|---|
onResult | (ids ) => void |
Returns
void
init()
init(): Promise<void>
Returns
Promise
<void
>
newAttachmentRecord()
abstract newAttachmentRecord(record?): Promise<AttachmentRecord>
Create a new AttachmentRecord, this gets called when the attachment id is not found in the database.
Parameters
Parameter | Type |
---|---|
record ? | Partial <AttachmentRecord > |
Returns
Promise
<AttachmentRecord
>
onAttachmentIdsChange()
abstract onAttachmentIdsChange(onUpdate): void
Takes in a callback that gets invoked with attachment IDs that need to be synced. In most cases this will contain a watch query.
Parameters
Parameter | Type |
---|---|
onUpdate | (ids ) => void |
Returns
void
Example
onAttachmentIdsChange(onUpdate) {
this.powersync.watch('SELECT photo_id as id FROM todos WHERE photo_id IS NOT NULL', [], {
onResult: (result) => onUpdate(result.rows?._array.map((r) => r.id) ?? [])
});
}
record()
record(id): Promise<AttachmentRecord>
Parameters
Parameter | Type |
---|---|
id | string |
Returns
Promise
<AttachmentRecord
>
saveToQueue()
saveToQueue(record): Promise<AttachmentRecord>
Parameters
Parameter | Type |
---|---|
record | Omit <AttachmentRecord , "timestamp" > |
Returns
Promise
<AttachmentRecord
>
trigger()
trigger(): void
Returns
void
update()
update(record): Promise<void>
Parameters
Parameter | Type |
---|---|
record | Omit <AttachmentRecord , "timestamp" > |
Returns
Promise
<void
>
uploadAttachment()
uploadAttachment(record): Promise<boolean>
Parameters
Parameter | Type |
---|---|
record | AttachmentRecord |
Returns
Promise
<boolean
>
watchAttachmentIds()
watchAttachmentIds(): Promise<void>
Returns
Promise
<void
>
watchDownloads()
watchDownloads(): void
Returns
void
watchUploads()
watchUploads(): void
Returns
void