AttachmentContext
Internal
AttachmentContext provides database operations for managing attachment records.
Provides methods to query, insert, update, and delete attachment records with proper transaction management through PowerSync.
Constructors
new AttachmentContext()
new AttachmentContext(
db,
tableName,
logger,
archivedCacheLimit): AttachmentContext
Creates a new AttachmentContext instance.
Parameters
| Parameter | Type | Description |
|---|---|---|
db | AbstractPowerSyncDatabase | PowerSync database instance |
tableName | undefined | string | Name of the table storing attachment records. Default: 'attachments' |
logger | ILogger | Logger instance for diagnostic output |
archivedCacheLimit | number | - |
Returns
Properties
| Property | Type | Description |
|---|---|---|
archivedCacheLimit | number | Maximum number of archived attachments to keep before cleanup |
db | AbstractPowerSyncDatabase | PowerSync database instance for executing queries |
logger | ILogger | Logger instance for diagnostic information |
tableName | string | Name of the database table storing attachment records |
Methods
clearQueue()
clearQueue(): Promise<void>
Returns
Promise<void>
deleteArchivedAttachments()
deleteArchivedAttachments(callback?): Promise<boolean>
Parameters
| Parameter | Type |
|---|---|
callback? | (attachments) => Promise<void> |
Returns
Promise<boolean>
deleteAttachment()
deleteAttachment(attachmentId): Promise<void>
Permanently deletes an attachment record from the database.
This operation removes the attachment record but does not delete the associated local or remote files. File deletion should be handled separately through the appropriate storage adapters.
Parameters
| Parameter | Type | Description |
|---|---|---|
attachmentId | string | Unique identifier of the attachment to delete |
Returns
Promise<void>
getActiveAttachments()
getActiveAttachments(): Promise<AttachmentRecord[]>
Retrieves all active attachments that require synchronization. Active attachments include those queued for upload, download, or delete. Results are ordered by timestamp in ascending order.
Returns
Promise<AttachmentRecord[]>
Promise resolving to an array of active attachment records
getArchivedAttachments()
getArchivedAttachments(): Promise<AttachmentRecord[]>
Retrieves all archived attachments.
Archived attachments are no longer referenced but haven't been permanently deleted. These are candidates for cleanup operations to free up storage space.
Returns
Promise<AttachmentRecord[]>
Promise resolving to an array of archived attachment records
getAttachment()
getAttachment(id): Promise<undefined | AttachmentRecord>
Parameters
| Parameter | Type |
|---|---|
id | string |
Returns
Promise<undefined | AttachmentRecord>
getAttachments()
getAttachments(): Promise<AttachmentRecord[]>
Retrieves all attachment records regardless of state. Results are ordered by timestamp in ascending order.
Returns
Promise<AttachmentRecord[]>
Promise resolving to an array of all attachment records
saveAttachments()
saveAttachments(attachments): Promise<void>
Saves multiple attachment records in a single transaction.
All updates are saved in a single batch after processing. If the attachments array is empty, no database operations are performed.
Parameters
| Parameter | Type | Description |
|---|---|---|
attachments | AttachmentRecord[] | Array of attachment records to save |
Returns
Promise<void>
upsertAttachment()
upsertAttachment(attachment, context): Promise<void>
Inserts or updates an attachment record within an existing transaction.
Performs an upsert operation (INSERT OR REPLACE). Must be called within an active database transaction context.
Parameters
| Parameter | Type | Description |
|---|---|---|
attachment | AttachmentRecord | The attachment record to upsert |
context | Transaction | Active database transaction context |
Returns
Promise<void>