Skip to main content

abstract AbstractAttachmentQueue<T>

Type parameters

Type parameterValue
T extends AttachmentQueueOptionsAttachmentQueueOptions

Constructors

new AbstractAttachmentQueue()

new AbstractAttachmentQueue<T>(options): AbstractAttachmentQueue<T>

Parameters

ParameterType
optionsT

Returns

AbstractAttachmentQueue<T>

Properties

PropertyType
downloadQueueSet<string>
downloadingboolean
initialSyncboolean
optionsT
uploadingboolean

Accessors

storageDirectory

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 table(): string

Returns

string

Methods

clearQueue()

clearQueue(): Promise<void>

Returns

Promise<void>


delete()

delete(record, tx?): Promise<void>

Parameters

ParameterType
recordAttachmentRecord
tx?Transaction

Returns

Promise<void>


downloadRecord()

downloadRecord(record): Promise<boolean>

Parameters

ParameterType
recordAttachmentRecord

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

ParameterType
filenamestring

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

ParameterType
filePathstring

Returns

string


getNextUploadRecord()

getNextUploadRecord(): Promise<AttachmentRecord>

Returns

Promise<AttachmentRecord>


idsToDownload()

idsToDownload(onResult): void

Parameters

ParameterType
onResult(ids) => void

Returns

void


idsToUpload()

idsToUpload(onResult): void

Parameters

ParameterType
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

ParameterType
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

ParameterType
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

ParameterType
idstring

Returns

Promise<AttachmentRecord>


saveToQueue()

saveToQueue(record): Promise<AttachmentRecord>

Parameters

ParameterType
recordOmit<AttachmentRecord, "timestamp">

Returns

Promise<AttachmentRecord>


trigger()

trigger(): void

Returns

void


update()

update(record): Promise<void>

Parameters

ParameterType
recordOmit<AttachmentRecord, "timestamp">

Returns

Promise<void>


uploadAttachment()

uploadAttachment(record): Promise<boolean>

Parameters

ParameterType
recordAttachmentRecord

Returns

Promise<boolean>


watchAttachmentIds()

watchAttachmentIds(): Promise<void>

Returns

Promise<void>


watchDownloads()

watchDownloads(): void

Returns

void


watchUploads()

watchUploads(): void

Returns

void