MCPcopy Create free account
hub / github.com/compozy/agh / deleteRawWithExecutor

Method deleteRawWithExecutor

internal/resources/kernel.go:612–655  ·  view source on GitHub ↗
(
	ctx context.Context,
	exec sqlExecutor,
	actor MutationActor,
	kind ResourceKind,
	id string,
	expectedVersion int64,
)

Source from the content-addressed store, hash-verified

610}
611
612func (k *Kernel) deleteRawWithExecutor(
613 ctx context.Context,
614 exec sqlExecutor,
615 actor MutationActor,
616 kind ResourceKind,
617 id string,
618 expectedVersion int64,
619) error {
620 if expectedVersion < 0 {
621 return fmt.Errorf("%w: expected_version cannot be negative: %d", ErrValidation, expectedVersion)
622 }
623
624 existing, found, err := lookupRecordWithExecutor(ctx, exec, kind, id)
625 if err != nil {
626 return err
627 }
628 if !found {
629 return ErrNotFound
630 }
631 if err := validateActorWriteAccess(actor, existing.Kind, existing.Scope); err != nil {
632 return err
633 }
634 if existing.Source != actor.Source {
635 return fmt.Errorf(
636 "%w: actor cannot mutate source %q/%q",
637 ErrPermissionDenied,
638 existing.Source.Kind,
639 existing.Source.ID,
640 )
641 }
642
643 result, err := exec.ExecContext(ctx, deleteRecordByVersionQuery, kind, id, expectedVersion)
644 if err != nil {
645 return fmt.Errorf("resources: delete record %q/%q: %w", kind, id, err)
646 }
647 rowsAffected, err := result.RowsAffected()
648 if err != nil {
649 return fmt.Errorf("resources: rows affected for delete %q/%q: %w", kind, id, err)
650 }
651 if rowsAffected == 0 {
652 return fmt.Errorf("%w: expected version %d", ErrConflict, expectedVersion)
653 }
654 return nil
655}
656
657func (k *Kernel) prepareListRaw(
658 actor MutationActor,

Callers 1

DeleteRawMethod · 0.95

Calls 4

lookupRecordWithExecutorFunction · 0.85
validateActorWriteAccessFunction · 0.85
RowsAffectedMethod · 0.80
ExecContextMethod · 0.65

Tested by

no test coverage detected