diff --git a/backend/internal/storage/postgres/attachments.go b/backend/internal/storage/postgres/attachments.go index 57c2efd..c824e8c 100644 --- a/backend/internal/storage/postgres/attachments.go +++ b/backend/internal/storage/postgres/attachments.go @@ -174,3 +174,27 @@ func (r *AttachmentRepo) DeletePending(ctx context.Context, id string) error { } return nil } + +func (r *AttachmentRepo) ExistingKeys(ctx context.Context, keys []string) ([]string, error) { + if len(keys) == 0 { + return []string{}, nil + } + const q = `SELECT object_key FROM attachments WHERE object_key = ANY($1::text[])` + rows, err := r.pool.Query(ctx, q, keys) + if err != nil { + return nil, mapError(err) + } + defer rows.Close() + + out := make([]string, 0, len(keys)) + for rows.Next() { + var k string + if err := rows.Scan(&k); err != nil { + return nil, mapError(err) + } + out = append(out, k) + } + return out, mapError(rows.Err()) +} + +var _ domain.AttachmentRepository = (*AttachmentRepo)(nil)