Packages

A delightful ORM (?) for Gleam! 🍳

Current section

Files

Jump to
ormlette src ormlette@templates@utils@to_string.erl
Raw

src/ormlette@templates@utils@to_string.erl

-module(ormlette@templates@utils@to_string).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([coltype/1, decode_type/1, to_file/3]).
-export_type([style/0]).
-type style() :: append | write.
-file("/Users/ashercohen/Desktop/gleam/ormlette/src/ormlette/templates/utils/to_string.gleam", 7).
-spec coltype(ormlette@schema@create:column()) -> binary().
coltype(Column) ->
case erlang:element(3, Column) of
int ->
<<"Int"/utf8>>;
bool ->
<<"Bool"/utf8>>;
string ->
<<"String"/utf8>>;
foreign_key ->
Hi = case erlang:element(8, Column) of
{some, Ref} ->
Col@1 = gleam@list:find(
erlang:element(3, erlang:element(2, Ref)),
fun(Col) ->
erlang:element(2, Col) =:= erlang:element(3, Ref)
end
),
case Col@1 of
{ok, Found_col} ->
coltype(Found_col);
{error, _} ->
erlang:error(#{gleam_error => panic,
message => <<"`panic` expression evaluated."/utf8>>,
module => <<"ormlette/templates/utils/to_string"/utf8>>,
function => <<"coltype"/utf8>>,
line => 19})
end;
none ->
erlang:error(#{gleam_error => panic,
message => <<"`panic` expression evaluated."/utf8>>,
module => <<"ormlette/templates/utils/to_string"/utf8>>,
function => <<"coltype"/utf8>>,
line => 22})
end;
serial ->
<<"Int"/utf8>>
end.
-file("/Users/ashercohen/Desktop/gleam/ormlette/src/ormlette/templates/utils/to_string.gleam", 29).
-spec decode_type(ormlette@schema@create:column()) -> binary().
decode_type(Column) ->
case erlang:element(3, Column) of
int ->
<<"decode.int"/utf8>>;
bool ->
<<"decode.bool"/utf8>>;
string ->
<<"decode.string"/utf8>>;
foreign_key ->
Hi = case erlang:element(8, Column) of
{some, Ref} ->
Col@1 = gleam@list:find(
erlang:element(3, erlang:element(2, Ref)),
fun(Col) ->
erlang:element(2, Col) =:= erlang:element(3, Ref)
end
),
case Col@1 of
{ok, Found_col} ->
decode_type(Found_col);
{error, _} ->
erlang:error(#{gleam_error => panic,
message => <<"`panic` expression evaluated."/utf8>>,
module => <<"ormlette/templates/utils/to_string"/utf8>>,
function => <<"decode_type"/utf8>>,
line => 41})
end;
none ->
erlang:error(#{gleam_error => panic,
message => <<"`panic` expression evaluated."/utf8>>,
module => <<"ormlette/templates/utils/to_string"/utf8>>,
function => <<"decode_type"/utf8>>,
line => 44})
end;
serial ->
<<"decode.int"/utf8>>
end.
-file("/Users/ashercohen/Desktop/gleam/ormlette/src/ormlette/templates/utils/to_string.gleam", 56).
-spec to_file(binary(), binary(), style()) -> {ok, nil} |
{error, simplifile:file_error()}.
to_file(Info, Path, Style) ->
simplifile_erl:create_directory(filepath:directory_name(Path)),
case Style of
append ->
_assert_subject = simplifile:append(Path, Info),
{ok, _} = case _assert_subject of
{ok, _} -> _assert_subject;
_assert_fail ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
value => _assert_fail,
module => <<"ormlette/templates/utils/to_string"/utf8>>,
function => <<"to_file"/utf8>>,
line => 60})
end;
write ->
_assert_subject@1 = simplifile:write(Path, Info),
{ok, _} = case _assert_subject@1 of
{ok, _} -> _assert_subject@1;
_assert_fail@1 ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
value => _assert_fail@1,
module => <<"ormlette/templates/utils/to_string"/utf8>>,
function => <<"to_file"/utf8>>,
line => 63})
end
end.