Skip to main content

@idpass/data-collect-core / PostgresAttachmentStorageAdapter

Class: PostgresAttachmentStorageAdapter

Defined in: storage/PostgresAttachmentStorageAdapter.ts:38

PostgreSQL implementation of the AttachmentStore for server-side attachment persistence.

Uses two tables:

  • attachments: Stores attachment metadata with indexes for efficient queries.
  • attachment_data: Stores binary file content as PostgreSQL BYTEA.

Supports multi-tenant isolation via tenant_id column.

Implements

Constructors

Constructor

new PostgresAttachmentStorageAdapter(connectionString, tenantId?): PostgresAttachmentStorageAdapter

Defined in: storage/PostgresAttachmentStorageAdapter.ts:43

Parameters

connectionString

string

tenantId?

string

Returns

PostgresAttachmentStorageAdapter

Methods

initialize()

initialize(): Promise<void>

Defined in: storage/PostgresAttachmentStorageAdapter.ts:53

Initializes the PostgreSQL tables for attachment storage. Creates tables if they do not already exist. Idempotent and safe to call multiple times.

Returns

Promise<void>


saveAttachment()

saveAttachment(metadata, data): Promise<void>

Defined in: storage/PostgresAttachmentStorageAdapter.ts:92

Saves attachment metadata and binary data.

Parameters

metadata

AttachmentMetadata

data

ArrayBuffer

Returns

Promise<void>

Implementation of

AttachmentStore.saveAttachment


getAttachment()

getAttachment(guid): Promise<{ metadata: AttachmentMetadata; data: ArrayBuffer; } | null>

Defined in: storage/PostgresAttachmentStorageAdapter.ts:139

Gets attachment metadata and binary data by GUID.

Parameters

guid

string

Returns

Promise<{ metadata: AttachmentMetadata; data: ArrayBuffer; } | null>

Implementation of

AttachmentStore.getAttachment


getAttachmentMetadata()

getAttachmentMetadata(guid): Promise<AttachmentMetadata | null>

Defined in: storage/PostgresAttachmentStorageAdapter.ts:159

Gets only the metadata for an attachment.

Parameters

guid

string

Returns

Promise<AttachmentMetadata | null>

Implementation of

AttachmentStore.getAttachmentMetadata


listAttachments()

listAttachments(entityGuid): Promise<AttachmentMetadata[]>

Defined in: storage/PostgresAttachmentStorageAdapter.ts:173

Lists all attachments for a specific entity within the current tenant.

Parameters

entityGuid

string

Returns

Promise<AttachmentMetadata[]>

Implementation of

AttachmentStore.listAttachments


deleteAttachment()

deleteAttachment(guid): Promise<void>

Defined in: storage/PostgresAttachmentStorageAdapter.ts:191

Deletes an attachment and its binary data. Only deletes if the attachment belongs to the current tenant.

Parameters

guid

string

Returns

Promise<void>

Implementation of

AttachmentStore.deleteAttachment


getPendingAttachments()

getPendingAttachments(tenantId): Promise<AttachmentMetadata[]>

Defined in: storage/PostgresAttachmentStorageAdapter.ts:211

Gets all attachments with 'pending' sync status for a tenant.

Parameters

tenantId

string

Returns

Promise<AttachmentMetadata[]>

Implementation of

AttachmentStore.getPendingAttachments


updateSyncStatus()

updateSyncStatus(guid, status): Promise<void>

Defined in: storage/PostgresAttachmentStorageAdapter.ts:228

Updates the sync status of an attachment.

Parameters

guid

string

status

"pending" | "uploaded" | "failed"

Returns

Promise<void>

Implementation of

AttachmentStore.updateSyncStatus


closeConnection()

closeConnection(): Promise<void>

Defined in: storage/PostgresAttachmentStorageAdapter.ts:242

Closes the PostgreSQL connection pool.

Returns

Promise<void>


clearStore()

clearStore(): Promise<void>

Defined in: storage/PostgresAttachmentStorageAdapter.ts:249

Clears all attachment data for the current tenant.

Returns

Promise<void>