Skip to main content

AbstractAttachmentQueue<T>

Type Parameters​

Type ParameterDefault type
T extends AttachmentQueueOptionsAttachmentQueueOptions

Constructors​

Constructor​

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

Parameters​

ParameterType
optionsT

Returns​

AbstractAttachmentQueue<T>

Properties​

PropertyType
downloadingboolean
downloadQueueSet<string>
initialSyncboolean
optionsT & { attachmentDirectoryName: string; attachmentTableName: string; cacheLimit: number; downloadAttachments: true; performInitialSync: true; syncInterval: number; }
uploadingboolean

Accessors​

logger​

Get Signature​

get logger(): PowerSyncLogger;
Returns​

PowerSyncLogger


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​

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 | null>;

Returns​

Promise<AttachmentRecord | null>


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 | null>;

Parameters​

ParameterType
idstring

Returns​

Promise<AttachmentRecord | null>


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