Skip to main content

src/gdo@transaction.erl

-module(gdo@transaction).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/gdo/transaction.gleam").
-export([is_active/1, 'begin'/1, commit/1, rollback/1]).
-export_type([transaction_state/0]).

-type transaction_state() :: idle | active.

-file("src/gdo/transaction.gleam", 8).
-spec is_active(transaction_state()) -> boolean().
is_active(State) ->
    case State of
        active ->
            true;

        idle ->
            false
    end.

-file("src/gdo/transaction.gleam", 15).
-spec 'begin'(transaction_state()) -> {ok, transaction_state()} |
    {error, gdo@error:error()}.
'begin'(State) ->
    case State of
        idle ->
            {ok, active};

        active ->
            {error,
                {transaction_error, <<"A transaction is already active."/utf8>>}}
    end.

-file("src/gdo/transaction.gleam", 22).
-spec commit(transaction_state()) -> {ok, transaction_state()} |
    {error, gdo@error:error()}.
commit(State) ->
    case State of
        active ->
            {ok, idle};

        idle ->
            {error,
                {transaction_error,
                    <<"Cannot commit without an active transaction."/utf8>>}}
    end.

-file("src/gdo/transaction.gleam", 30).
-spec rollback(transaction_state()) -> {ok, transaction_state()} |
    {error, gdo@error:error()}.
rollback(State) ->
    case State of
        active ->
            {ok, idle};

        idle ->
            {error,
                {transaction_error,
                    <<"Cannot roll back without an active transaction."/utf8>>}}
    end.