Packages

A delightful ORM (?) for Gleam! 🍳

Current section

Files

Jump to
ormlette src ormlette.erl
Raw

src/ormlette.erl

-module(ormlette).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([run_module/1, main/0]).
-export_type([gen/0]).
-type gen() :: meta | orm.
-file("/Users/ashercohen/Desktop/gleam/ormlette/src/ormlette.gleam", 28).
-spec meta_command() -> clip:command(gen()).
meta_command() ->
_pipe = clip:return(meta),
clip:add_help(
_pipe,
<<"gen meta"/utf8>>,
<<"Generates metadata for Records using Glerd. Makes it so we can have proper __ FORGET NAME RN"/utf8>>
).
-file("/Users/ashercohen/Desktop/gleam/ormlette/src/ormlette.gleam", 38).
-spec orm_command() -> clip:command(gen()).
orm_command() ->
_pipe = clip:return(orm),
clip:add_help(
_pipe,
<<"gen orm"/utf8>>,
<<"Generates the ORM decoders, types, and access types. RUN BEFORE gen meta"/utf8>>
).
-file("/Users/ashercohen/Desktop/gleam/ormlette/src/ormlette.gleam", 48).
-spec command() -> clip:command(gen()).
command() ->
clip:subcommands(
[{<<"meta"/utf8>>, meta_command()}, {<<"orm"/utf8>>, orm_command()}]
).
-file("/Users/ashercohen/Desktop/gleam/ormlette/src/ormlette.gleam", 82).
-spec run_module(binary()) -> {ok, nil} | {error, nil}.
run_module(Mod) ->
_assert_subject = simplifile:current_directory(),
{ok, Cwd} = 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"/utf8>>,
function => <<"run_module"/utf8>>,
line => 83})
end,
case shellout:command(
<<"gleam"/utf8>>,
[<<"run"/utf8>>, <<"-m"/utf8>>, Mod],
<<Cwd/binary, "/"/utf8>>,
[]
) of
{ok, _} ->
{ok, nil};
{error, _} ->
{error, nil}
end.
-file("/Users/ashercohen/Desktop/gleam/ormlette/src/ormlette.gleam", 54).
-spec main() -> nil.
main() ->
Result = begin
_pipe = command(),
_pipe@1 = clip:add_help(
_pipe,
<<"gen"/utf8>>,
<<"Run some codegen!"/utf8>>
),
clip:run(_pipe@1, erlang:element(4, argv:load()))
end,
case Result of
{error, E} ->
gleam@io:println_error(<<"ERR"/utf8, E/binary>>);
{ok, Args} ->
Results = case Args of
orm ->
ormlette@cli@generate:create_generate_file(),
run_module(<<"eggs/generate"/utf8>>),
gleam@io:println(<<"Ran module eggs/generate"/utf8>>);
meta ->
run_module(<<"glerd"/utf8>>),
gleam@io:println(<<"Ran module glerd"/utf8>>)
end,
gleam@io:println(<<"Done!"/utf8>>)
end.