Skuld.Effects.DBTransaction.Noop (skuld v0.1.15)

View Source

No-op transaction handler for the DBTransaction effect.

Does not actually create a transaction - useful for testing or when you want to use code that expects a transaction handler but don't need actual transaction semantics.

Behavior

For transact(comp):

  • Normal completion → returns result (no actual commit)
  • Throw/Suspend → propagates normally (no actual rollback)
  • Explicit rollback(reason) → returns {:rolled_back, reason} (no actual rollback)

Example

alias Skuld.Comp
alias Skuld.Effects.DBTransaction
alias Skuld.Effects.DBTransaction.Noop, as: NoopTx

# In tests, use Noop instead of Ecto
comp do
  result <- DBTransaction.transact(comp do
    _ <- do_something()
    return(:ok)
  end)
  return(result)
end
|> NoopTx.with_handler()
|> Comp.run!()

Summary

Functions

Install Noop handler via catch clause syntax.

Install a no-op transaction handler.

Functions

__handle__(comp, config)

Install Noop handler via catch clause syntax.

catch
  DBTransaction.Noop -> nil

with_handler(comp)

Install a no-op transaction handler.

Handles transact operations by simply running the inner computation without any actual transaction wrapping. The rollback/1 operation returns {:rolled_back, reason} without actually rolling back anything.

Example

comp do
  result <- DBTransaction.transact(comp do
    _ <- DBTransaction.rollback(:test_reason)
    return(:never_reached)
  end)
  return(result)
end
|> DBTransaction.Noop.with_handler()
|> Comp.run!()
#=> {:rolled_back, :test_reason}