AttachmentContext
Experimental Alpha
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
Constructor
new AttachmentContext(
db,
tableName?,
logger,
archivedCacheLimit): AttachmentContext;
Alpha
Creates a new AttachmentContext instance.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
db | CommonPowerSyncDatabase | undefined | PowerSync database instance |
tableName | string | 'attachments' | Name of the table storing attachment records. Default: 'attachments' |
logger | PowerSyncLogger | undefined | Logger instance for diagnostic output |
archivedCacheLimit | number | undefined | - |
Returns
AttachmentContext
Properties
| Property | Modifier | Type | Default value | Description |
|---|---|---|---|---|
archivedCacheLimit | readonly | number | 100 | Alpha Maximum number of archived attachments to keep before cleanup |
db | readonly | CommonPowerSyncDatabase | undefined | Alpha PowerSync database instance for executing queries |
logger | readonly | PowerSyncLogger | undefined | Alpha Logger instance for diagnostic information |
tableName | readonly | string | undefined | Alpha Name of the database table storing attachment records |
Methods
clearQueue()
clearQueue(): Promise<void>;
Alpha Experimental
Returns
Promise<void>
deleteArchivedAttachments()
deleteArchivedAttachments(callback?): Promise<boolean>;
Alpha Experimental
Parameters
| Parameter | Type |
|---|---|
callback? | (attachments) => Promise<void> |
Returns
Promise<boolean>
deleteAttachment()
deleteAttachment(attachmentId): Promise<void>;
Alpha
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[]>;
Alpha
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[]>;
Alpha
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<AttachmentRecord | undefined>;
Alpha Experimental
Parameters
| Parameter | Type |
|---|---|
id | string |
Returns
Promise<AttachmentRecord | undefined>
getAttachments()
getAttachments(): Promise<AttachmentRecord[]>;
Alpha
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>;
Alpha
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>;
Alpha
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>