Arcadic.Transaction (Arcadic v0.1.0)

Copy Markdown View Source

Session transactions. transaction/3 begins a session, runs the fun with a session-scoped conn, and commits on a normal return. On an exception it rolls back and RERAISES (postgrex semantics — unexpected failures propagate, they do not become {:error, …}). Use rollback/2 for an intentional abort that yields {:error, reason}. Nesting raises — there is no verified HTTP savepoint contract.

Summary

Functions

Begin a session; returns a session-scoped conn.

Commit a session-scoped conn.

Roll back a session-scoped conn.

Abort the current transaction with reason; the enclosing transaction/3 returns {:error, reason}.

Run fun inside a session transaction. Opts: :isolation (:read_committed | :repeatable_read).

Functions

begin(conn, opts \\ [])

@spec begin(
  Arcadic.Conn.t(),
  keyword()
) ::
  {:ok, Arcadic.Conn.t()}
  | {:error, Arcadic.Error.t() | Arcadic.TransportError.t()}

Begin a session; returns a session-scoped conn.

commit(conn)

@spec commit(Arcadic.Conn.t()) ::
  :ok | {:error, Arcadic.Error.t() | Arcadic.TransportError.t()}

Commit a session-scoped conn.

rollback(conn)

@spec rollback(Arcadic.Conn.t()) ::
  :ok | {:error, Arcadic.Error.t() | Arcadic.TransportError.t()}

Roll back a session-scoped conn.

rollback(conn, reason)

@spec rollback(Arcadic.Conn.t(), term()) :: no_return()

Abort the current transaction with reason; the enclosing transaction/3 returns {:error, reason}.

transaction(conn, fun, opts \\ [])

@spec transaction(Arcadic.Conn.t(), (Arcadic.Conn.t() -> result), keyword()) ::
  {:ok, result}
  | {:error, Arcadic.Error.t() | Arcadic.TransportError.t() | term()}
when result: var

Run fun inside a session transaction. Opts: :isolation (:read_committed | :repeatable_read).