feat(storage): lab5 add CreateInTx for transactional outbox support
This commit is contained in:
@@ -44,6 +44,7 @@ type AttachmentRepository interface {
|
|||||||
ListStalePending(ctx context.Context, olderThan time.Time, limit int) ([]Attachment, error)
|
ListStalePending(ctx context.Context, olderThan time.Time, limit int) ([]Attachment, error)
|
||||||
ExistingKeys(ctx context.Context, keys []string) ([]string, error)
|
ExistingKeys(ctx context.Context, keys []string) ([]string, error)
|
||||||
DeletePending(ctx context.Context, id string) error
|
DeletePending(ctx context.Context, id string) error
|
||||||
|
CreateInTx(ctx context.Context, tx Tx, a *Attachment) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type OutboxRepository interface {
|
type OutboxRepository interface {
|
||||||
|
|||||||
@@ -51,6 +51,23 @@ func (r *AttachmentRepo) Create(ctx context.Context, a *domain.Attachment) error
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *AttachmentRepo) CreateInTx(ctx context.Context, tx domain.Tx, a *domain.Attachment) error {
|
||||||
|
const q = `
|
||||||
|
INSERT INTO attachments
|
||||||
|
(id, chat_id, owner_id, filename, content_type, size_bytes, sha256,
|
||||||
|
object_key, status, error_code,
|
||||||
|
attempts, pipeline_version, staging_key,
|
||||||
|
created_at, updated_at)
|
||||||
|
VALUES ($1::uuid, $2::uuid, $3::uuid, $4, $5, $6, $7, $8, $9, NULL,
|
||||||
|
0, $10, $11, $12, $12)
|
||||||
|
`
|
||||||
|
return tx.Exec(ctx, q,
|
||||||
|
a.ID, a.ChatID, a.OwnerID, a.Filename, a.ContentType, a.SizeBytes,
|
||||||
|
a.SHA256, a.ObjectKey, string(a.Status),
|
||||||
|
a.PipelineVersion, a.StagingKey, a.CreatedAt,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
func (r *AttachmentRepo) GetByID(ctx context.Context, id string) (*domain.Attachment, error) {
|
func (r *AttachmentRepo) GetByID(ctx context.Context, id string) (*domain.Attachment, error) {
|
||||||
const q = `
|
const q = `
|
||||||
SELECT id, chat_id, owner_id, filename, content_type, size_bytes, sha256,
|
SELECT id, chat_id, owner_id, filename, content_type, size_bytes, sha256,
|
||||||
|
|||||||
Reference in New Issue
Block a user