Current section
Files
Jump to
Current section
Files
src/cigogne@internal@utils.erl
-module(cigogne@internal@utils).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([result_guard/3, describe_decode_error/1, describe_query_error/1, describe_transaction_error/1, tempo_to_pog_timestamp/1, pog_to_tempo_timestamp/1, pog_timestamp_to_string/1, tempo_epoch/0]).
-file("/home/runner/work/cigogne/cigogne/src/cigogne/internal/utils.gleam", 12).
-spec result_guard({ok, LVJ} | {error, any()}, LVN, fun((LVJ) -> LVN)) -> LVN.
result_guard(Result, Otherwise, Callback) ->
case Result of
{error, _} ->
Otherwise;
{ok, V} ->
Callback(V)
end.
-file("/home/runner/work/cigogne/cigogne/src/cigogne/internal/utils.gleam", 52).
-spec describe_decode_error(gleam@dynamic@decode:decode_error()) -> binary().
describe_decode_error(Error) ->
<<<<<<<<<<<<"Expecting : "/utf8, (erlang:element(2, Error))/binary>>/binary,
", Got : "/utf8>>/binary,
(erlang:element(3, Error))/binary>>/binary,
" [at "/utf8>>/binary,
(begin
_pipe = erlang:element(4, Error),
gleam@string:join(_pipe, <<"/"/utf8>>)
end)/binary>>/binary,
"]"/utf8>>.
-file("/home/runner/work/cigogne/cigogne/src/cigogne/internal/utils.gleam", 23).
-spec describe_query_error(pog:query_error()) -> binary().
describe_query_error(Error) ->
case Error of
connection_unavailable ->
<<"CONNECTION UNAVAILABLE"/utf8>>;
{constraint_violated, Message, _, _} ->
Message;
{postgresql_error, _, _, Message@1} ->
<<"Postgresql error : "/utf8, Message@1/binary>>;
{unexpected_argument_count, Expected, Got} ->
<<<<<<<<"Expected "/utf8,
(erlang:integer_to_binary(Expected))/binary>>/binary,
" arguments, got "/utf8>>/binary,
(erlang:integer_to_binary(Got))/binary>>/binary,
" !"/utf8>>;
{unexpected_argument_type, Expected@1, Got@1} ->
<<<<<<<<"Expected argument of type "/utf8, Expected@1/binary>>/binary,
", got "/utf8>>/binary,
Got@1/binary>>/binary,
" !"/utf8>>;
{unexpected_result_type, Errs} ->
<<"Unexpected result type ! \n"/utf8,
(begin
_pipe = gleam@list:map(Errs, fun describe_decode_error/1),
gleam@string:join(_pipe, <<"\n"/utf8>>)
end)/binary>>;
query_timeout ->
<<"Query Timeout"/utf8>>
end.
-file("/home/runner/work/cigogne/cigogne/src/cigogne/internal/utils.gleam", 44).
-spec describe_transaction_error(pog:transaction_error()) -> binary().
describe_transaction_error(Error) ->
case Error of
{transaction_query_error, Suberror} ->
describe_query_error(Suberror);
{transaction_rolled_back, Message} ->
<<"Transaction rolled back : "/utf8, Message/binary>>
end.
-file("/home/runner/work/cigogne/cigogne/src/cigogne/internal/utils.gleam", 62).
-spec tempo_to_pog_timestamp(tempo:naive_date_time()) -> pog:timestamp().
tempo_to_pog_timestamp(From) ->
As_tuple = begin
_pipe = From,
tempo@naive_datetime:to_tuple(_pipe)
end,
{timestamp,
{date,
erlang:element(1, erlang:element(1, As_tuple)),
erlang:element(2, erlang:element(1, As_tuple)),
erlang:element(3, erlang:element(1, As_tuple))},
{time,
erlang:element(1, erlang:element(2, As_tuple)),
erlang:element(2, erlang:element(2, As_tuple)),
erlang:element(3, erlang:element(2, As_tuple)),
0}}.
-file("/home/runner/work/cigogne/cigogne/src/cigogne/internal/utils.gleam", 79).
-spec pog_to_tempo_date(pog:date()) -> {ok, tempo:date()} | {error, nil}.
pog_to_tempo_date(From) ->
_pipe = tempo@date:new(
erlang:element(2, From),
erlang:element(3, From),
erlang:element(4, From)
),
gleam@result:replace_error(_pipe, nil).
-file("/home/runner/work/cigogne/cigogne/src/cigogne/internal/utils.gleam", 83).
-spec pog_to_tempo_time(pog:time()) -> {ok, tempo:time()} | {error, nil}.
pog_to_tempo_time(From) ->
_pipe = tempo@time:new(
erlang:element(2, From),
erlang:element(3, From),
erlang:element(4, From)
),
gleam@result:replace_error(_pipe, nil).
-file("/home/runner/work/cigogne/cigogne/src/cigogne/internal/utils.gleam", 71).
-spec pog_to_tempo_timestamp(pog:timestamp()) -> {ok, tempo:naive_date_time()} |
{error, nil}.
pog_to_tempo_timestamp(From) ->
gleam@result:'try'(
pog_to_tempo_date(erlang:element(2, From)),
fun(Date) ->
gleam@result:'try'(
pog_to_tempo_time(erlang:element(3, From)),
fun(Time) -> {ok, tempo@naive_datetime:new(Date, Time)} end
)
end
).
-file("/home/runner/work/cigogne/cigogne/src/cigogne/internal/utils.gleam", 87).
-spec pog_timestamp_to_string(pog:timestamp()) -> binary().
pog_timestamp_to_string(Value) ->
<<<<(begin
_pipe = [erlang:element(2, erlang:element(2, Value)),
erlang:element(3, erlang:element(2, Value)),
erlang:element(4, erlang:element(2, Value))],
_pipe@1 = gleam@list:map(_pipe, fun erlang:integer_to_binary/1),
gleam@string:join(_pipe@1, <<"-"/utf8>>)
end)/binary,
" "/utf8>>/binary,
(begin
_pipe@2 = [erlang:element(2, erlang:element(3, Value)),
erlang:element(3, erlang:element(3, Value)),
erlang:element(4, erlang:element(3, Value))],
_pipe@3 = gleam@list:map(_pipe@2, fun(V) -> case V of
V@1 when V@1 < 10 ->
<<"0"/utf8, (erlang:integer_to_binary(V@1))/binary>>;
_ ->
erlang:integer_to_binary(V)
end end),
gleam@string:join(_pipe@3, <<":"/utf8>>)
end)/binary>>.
-file("/home/runner/work/cigogne/cigogne/src/cigogne/internal/utils.gleam", 102).
-spec tempo_epoch() -> tempo:naive_date_time().
tempo_epoch() ->
tempo@naive_datetime:literal(<<"1970-01-01 00:00:00"/utf8>>).