Current section
Files
Jump to
Current section
Files
src/galchemy@session@postgres.erl
-module(galchemy@session@postgres).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src\\galchemy\\session\\postgres.gleam").
-export([with_transaction/3, 'begin'/2, flush/1, commit/1]).
-export_type([postgres_transaction_error/1]).
-type postgres_transaction_error(PPK) :: {transaction_error,
pog:transaction_error(PPK)}.
-file("src\\galchemy\\session\\postgres.gleam", 13).
-spec with_transaction(
pog:connection(),
galchemy@session@runtime:session(),
fun((galchemy@session@transaction:transaction_session(pog:connection())) -> {ok,
PPM} |
{error, PPN})
) -> {ok, PPM} | {error, postgres_transaction_error(PPN)}.
with_transaction(Connection, Session, Callback) ->
case pog:transaction(
Connection,
fun(Tx_connection) ->
Callback(
galchemy@session@transaction:'begin'(Tx_connection, Session)
)
end
) of
{ok, Result} ->
{ok, Result};
{error, Error} ->
{error, {transaction_error, Error}}
end.
-file("src\\galchemy\\session\\postgres.gleam", 29).
-spec 'begin'(pog:connection(), galchemy@session@runtime:session()) -> galchemy@session@transaction:transaction_session(pog:connection()).
'begin'(Connection, Session) ->
galchemy@session@transaction:'begin'(Connection, Session).
-file("src\\galchemy\\session\\postgres.gleam", 62).
-spec execute_query(galchemy@ast@query:'query'(), pog:connection()) -> {ok,
pog:returned(nil)} |
{error, galchemy@sql@postgres:postgres_error()}.
execute_query(Next_query, Connection) ->
galchemy@sql@postgres:execute(Next_query, Connection).
-file("src\\galchemy\\session\\postgres.gleam", 69).
-spec summarize_flush(
galchemy@session@execution:flush_execution(pog:returned(nil))
) -> pog:returned(nil).
summarize_flush(Flush_result) ->
All_results = begin
_pipe = galchemy@session@execution:queries(Flush_result),
gleam@list:fold(
_pipe,
0,
fun(Acc, Executed) ->
Acc + erlang:element(2, erlang:element(3, Executed))
end
)
end,
{returned, All_results, []}.
-file("src\\galchemy\\session\\postgres.gleam", 36).
-spec flush(galchemy@session@transaction:transaction_session(pog:connection())) -> {ok,
{pog:returned(nil),
galchemy@session@transaction:transaction_session(pog:connection())}} |
{error,
galchemy@session@transaction:transaction_error(galchemy@sql@postgres:postgres_error())}.
flush(Transaction_session) ->
case galchemy@session@transaction:flush(
Transaction_session,
fun execute_query/2
) of
{ok, {Flush_result, Next_transaction}} ->
{ok, {summarize_flush(Flush_result), Next_transaction}};
{error, Error} ->
{error, Error}
end.
-file("src\\galchemy\\session\\postgres.gleam", 49).
-spec commit(galchemy@session@transaction:transaction_session(pog:connection())) -> {ok,
{pog:returned(nil), galchemy@session@runtime:session()}} |
{error,
galchemy@session@transaction:transaction_error(galchemy@sql@postgres:postgres_error())}.
commit(Transaction_session) ->
case galchemy@session@transaction:commit(
Transaction_session,
fun execute_query/2
) of
{ok, {Flush_result, Next_session}} ->
{ok, {summarize_flush(Flush_result), Next_session}};
{error, Error} ->
{error, Error}
end.