Skip to content

Commit

Permalink
fix issue #80
Browse files Browse the repository at this point in the history
  • Loading branch information
schonfinkel committed Dec 4, 2024
1 parent da9d01a commit 543fee0
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 121 deletions.
2 changes: 1 addition & 1 deletion server/apps/server/src/server.app.src
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
sasl,
csv,
epgsql,
erlando
erlandono
]},
{env, []},
{modules, []},
Expand Down
2 changes: 1 addition & 1 deletion server/lib/database/rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
{deps, [
{pure_migrations, "1.3.0"},
{epgsql, "4.7.1"},
{erlando, "3.1.1"}
{erlandono, "3.1.2"}
]}.
2 changes: 1 addition & 1 deletion server/lib/database/src/database.app.src
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
pure_migrations,
epgsql,
sasl,
erlando
erlandono
]},
{env, []},
{modules, [database, database_migrations, database_utils, postgres_m]},
Expand Down
92 changes: 0 additions & 92 deletions server/lib/database/src/database_migration.erl

This file was deleted.

47 changes: 31 additions & 16 deletions server/lib/database/src/postgres_m.erl
Original file line number Diff line number Diff line change
@@ -1,25 +1,40 @@
-module(postgres_m).

-behaviour(monad).

-export(['>>='/2, return/1, fail/1]).

-type(monad(_A) :: {{'ok', any(), any()}, 'select'}
| {{'ok', any()}, 'delete'}
| {{'ok', any()}, 'insert'}
| {{'ok', any(), any(), any()}, 'insert'}
| {{'ok', any()}, 'update'}
| {{'error', any()}, any()}).
-include_lib("erlando/include/monad_specs.hrl").
% This only makes sense if we export it or use dialyzer
%-type monad(_A) ::
% {{ok, any(), any()}, select} |
% {{ok, any()}, delete} |
% {{ok, any()}, insert} |
% {{ok, any(), any(), any()}, insert} |
% {{ok, any()}, update} |
% {{error, any()}, any()}.

-spec return(X) -> Result
when X :: any(),
Result :: {ok, any()}.
return(X) ->
{ok, X}.

return(X) -> {ok, X}.
fail(X) -> {error, X}.
-spec fail(X) -> Result
when X :: any(),
Result :: {error, any()}.
fail(X) ->
{error, X}.

'>>='({{ok, FullColumns, Values}, select}, Fun) -> Fun({FullColumns, Values});
'>>='({{ok, Count}, delete}, Fun) -> Fun(Count);
'>>='({{ok, Count}, insert}, Fun) -> Fun(Count);
'>>='({{ok, _, _, _}, insert}, _) -> fail("Unexpected use of Insert on Server side");
'>>='({{ok, Count}, update}, Fun) -> Fun(Count);
'>>='({{error, Error}, Tag}, _) ->
'>>='({{ok, FullColumns, Values}, select}, Fun) ->
Fun({FullColumns, Values});
'>>='({{ok, Count}, delete}, Fun) ->
Fun(Count);
'>>='({{ok, Count}, insert}, Fun) ->
Fun(Count);
'>>='({{ok, _, _, _}, insert}, _) ->
fail("Unexpected use of Insert on Server side");
'>>='({{ok, Count}, update}, Fun) ->
Fun(Count);
'>>='({{error, Error}, Tag}, _) ->
io:format("Tag: ~p\nError: ~p\n", [Error, Tag]),
fail("Unexpected error (operation or PSQL) on Server side").

12 changes: 6 additions & 6 deletions server/rebar-deps.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ let
};
beamDeps = [ ];
};
erlando = builder {
name = "erlando";
version = "3.1.1";
erlandono = builder {
name = "erlandono";
version = "3.1.2";
src = fetchHex {
pkg = "erlando";
version = "3.1.1";
sha256 = "sha256-ljPLSXjb14gn+nbqTDsL0kz71N2a9ICI6SLnEVSUo0Q=";
pkg = "erlandono";
version = "3.1.2";
sha256 = "sha256-ED+m50Ky73TIeBmi6P06r2O2tvjixibrEEZIhWVj514=";
};
beamDeps = [ ];
};
Expand Down
2 changes: 1 addition & 1 deletion server/rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{deps, [
{epgsql, "4.7.1"},
{pc, "1.15.0"},
{erlando, "3.1.1"},
{erlandono, "3.1.2"},
{csv, "3.0.3", {pkg, csve}}
]}.

Expand Down
6 changes: 3 additions & 3 deletions server/rebar.lock
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{"1.2.0",
[{<<"csv">>,{pkg,<<"csve">>,<<"3.0.3">>},0},
{<<"epgsql">>,{pkg,<<"epgsql">>,<<"4.7.1">>},0},
{<<"erlando">>,{pkg,<<"erlando">>,<<"3.1.1">>},0},
{<<"erlandono">>,{pkg,<<"erlandono">>,<<"3.1.2">>},0},
{<<"pc">>,{pkg,<<"pc">>,<<"1.15.0">>},0},
{<<"pure_migrations">>,{pkg,<<"pure_migrations">>,<<"1.3.0">>},0}]}.
[
{pkg_hash,[
{<<"csv">>, <<"69E7D9B3FDC72016644368762C6A3E6CBFEB85BCCADBF1BD99AB6C827E360E04">>},
{<<"epgsql">>, <<"D4E47CAE46C18C8AFA88E34D59A9B4BAE16368D7CE1EB3DA24FA755EB28393EB">>},
{<<"erlando">>, <<"50E54F9A9DFEC564DDFEB7FC7129F80F491856F5E07686F405CEF4E970BDFE46">>},
{<<"erlandono">>, <<"65C546236E33946573C76349954D142DE8ED4986AC3D04BD1DBA7676E1E64F38">>},
{<<"pc">>, <<"0DE7D4DF1BB23897E27965FC134DC63156DD2E5B512A9536CB7004D984400A45">>},
{<<"pure_migrations">>, <<"B758A62A9EDD6C1B40B668F4D6CE9E5588DBD4D99A4469BCE46BC7089B594AF7">>}]},
{pkg_hash_ext,[
{<<"csv">>, <<"741D1A55AABADAA3E0FE13051050101A73E90C4570B9F9403A939D9546813521">>},
{<<"epgsql">>, <<"B6D86B7DC42C8555B1D4E20880E5099D6D6D053148000E188E548F98E4E01836">>},
{<<"erlando">>, <<"9633CB4978DBD78827FA76EA4C3B0BD24CFBD4DD9AF48088E922E7115494A344">>},
{<<"erlandono">>, <<"103FA6E742B2EF74C87819A2E8FD3AAF63B6B6F8E2C626EB104648856563E75E">>},
{<<"pc">>, <<"4C0FAD4F6437CAE353D517DA218FE78347B8FFA44B9817887494CAAAE54595B3">>},
{<<"pure_migrations">>, <<"00269DE0A1A9BBE1B7681EC1F3FA59EE9D8081582226A94C633E6F94B5C88BC3">>}]}
].

0 comments on commit 543fee0

Please sign in to comment.