Skip to content

Commit

Permalink
merge synlay-feature/rebar3_support
Browse files Browse the repository at this point in the history
  • Loading branch information
danikp committed Oct 11, 2016
2 parents 7ac9e39 + bcad499 commit 35c6209
Show file tree
Hide file tree
Showing 8 changed files with 180 additions and 37 deletions.
21 changes: 9 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@ GIT = git
REBAR_VER = 3.2.0
DB_CONFIG_DIR=priv/test_db_config

.PHONY: deps get-deps test
.PHONY: test

all: compile

compile:
@$(REBAR) compile

boss_db:
@$(REBAR) compile skip_deps=true

rebar_src:
@rm -rf $(PWD)/rebar_src
@$(GIT) clone https://github.com/erlang/rebar3.git rebar_src
Expand All @@ -28,6 +25,7 @@ get-deps:
deps:
@$(REBAR) compile

.PHONY: dialyze
dialyze:
@$(REBAR) dialyzer || [ $$? -eq 1 ];

Expand All @@ -36,24 +34,23 @@ clean:
rm -fv erl_crash.dump

test:
@$(REBAR) skip_deps=true eunit
@$(REBAR) eunit

compile_db_test:
@$(REBAR) clean skip_deps=true
@$(REBAR) --config "rebar.test.config" compile skip_deps=true
@$(REBAR) as test, boss_test do clean, compile

test_db_mock: compile_db_test
$(ERL) -pa ebin -pa deps/*/ebin -run boss_db_test start -config $(DB_CONFIG_DIR)/mock -noshell
$(ERL) -pa _build/test+boss_test/lib/*/ebin -run boss_db_test start -config $(DB_CONFIG_DIR)/mock -noshell

test_db_mysql: compile_db_test
$(ERL) -pa ebin -pa deps/*/ebin -run boss_db_test start -config $(DB_CONFIG_DIR)/mysql -noshell
$(ERL) -pa _build/test+boss_test/lib/*/ebin -run boss_db_test start -config $(DB_CONFIG_DIR)/mysql -noshell

test_db_pgsql: compile_db_test
$(ERL) -pa ebin -pa deps/*/ebin -run boss_db_test start -config $(DB_CONFIG_DIR)/pgsql -noshell
$(ERL) -pa _build/test+boss_test/lib/*/ebin -run boss_db_test start -config $(DB_CONFIG_DIR)/pgsql -noshell

test_db_mongodb: compile_db_test
echo "db.boss_db_test_models.remove();"|mongo boss_test
$(ERL) -pa ebin -pa deps/*/ebin -run boss_db_test start -config $(DB_CONFIG_DIR)/mongodb -noshell
$(ERL) -pa _build/test+boss_test/lib/*/ebin -run boss_db_test start -config $(DB_CONFIG_DIR)/mongodb -noshell

test_db_riak: compile_db_test
$(ERL) -pa ebin -pa deps/*/ebin -run boss_db_test start -config $(DB_CONFIG_DIR)/riak -noshell
$(ERL) -pa _build/test+boss_test/lib/*/ebin -run boss_db_test start -config $(DB_CONFIG_DIR)/riak -noshell
15 changes: 14 additions & 1 deletion rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,18 @@
]}.

{cover_enabled, true}.
{plugins, [rebar3_hex]}.
{plugins, [rebar3_hex, rebar3_proper]}.

{profiles,
[{test, [
{deps, [
{proper, "1.1.1-beta"}
]}
]},
{boss_test, [
{erl_opts, [{d, boss_test}]}
]},
{prod, [
{erl_opts, [warnings_as_errors]}
]}
]}.
48 changes: 48 additions & 0 deletions rebar.config.script
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
case erlang:function_exported(rebar3, main, 1) of
true -> % rebar3
CONFIG;
false -> % rebar 2.x or older
%% Rebuild deps, possibly including those that have been moved to
%% profiles
[{deps, [
{lager, ".*", {git, "https://github.com/basho/lager.git", {tag, "2.1.0"}}},
{erlando, ".*", {git, "https://github.com/ChicagoBoss/erlando.git", {tag, "b0b77dd9b9"}}},
{aleppo, ".*", {git, "https://github.com/ErlyORM/aleppo.git", {tag, "ee1056f740"}}},
{medici, ".*", {git, "https://github.com/ErlyORM/medici.git", {tag, "bb6167459d"}}},

% Different version of mongodb driver and bson breaking compilation
% on different Erlang version. So disabling them by default. Uncomment one
% of options below, if you need mongodb driver
% for Erlang = 17
%{bson, ".*", {git, "https://github.com/comtihon/bson-erlang", {branch, "legacy"}}},
%{mongodb, ".*", {git, "https://github.com/comtihon/mongodb-erlang", {tag, "v0.7.9"}}},
% for Erlang >= 18
%{mongodb, ".*", {git, "https://github.com/comtihon/mongodb-erlang", {tag, "v0.7.9"}}},

% riak_pb not compatible with Erlang 18, so commented for now
% uncomment line below if you need Riak support and have Erlang < 18
%{riakc, ".*", {git, "https://github.com/ErlyORM/riak-erlang-client.git", {tag, "1.3.0-boss"}}},

{ddb, ".*", {git, "https://github.com/ErlyORM/ddb.git", {tag, "v0.1.3"}}},
{epgsql, ".*", {git, "https://github.com/epgsql/epgsql.git", {tag, "c7dfb064811"}}},
{erlmc, ".*", {git, "https://github.com/layerhq/erlmc.git", {tag, "1c17552"}}},
{mysql, ".*", {git, "https://github.com/ErlyORM/erlang-mysql-driver.git", {tag, "v0.0.1"}}},
{poolboy, ".*", {git, "https://github.com/devinus/poolboy.git", {tag, "1.5.1"}}},
{uuid, ".*", {git, "https://github.com/avtobiff/erlang-uuid.git", {tag, "v0.5.0"}}},
{redo, ".*", {git, "https://github.com/heroku/redo.git", {tag, "936a3c5"}}},
% boss_branch for ets_cache
{ets_cache, ".*", {git, "https://github.com/cuongth/ets_cache.git", {tag, "c7a17204cd"}}},
{proper, ".*", {git, "https://github.com/manopapad/proper.git", {tag, "c8c73ee23b"}}},
{dh_date, ".*", {git, "https://github.com/zotonic/dh_date.git", {tag, "473ad8c473"}}},
{tiny_pq, ".*", {git, "https://github.com/ChicagoBoss/tiny_pq.git", {tag, "v0.8.15"}}},
{boss_test, ".*", {git, "https://github.com/ChicagoBoss/boss_test.git", {tag, "0.0.1"}}}
]}
,{plugins, [rebar_ct]}
,{erl_opts, [
debug_info,
{parse_transform, lager_transform},
{parse_transform, cut},
{parse_transform, do},
{parse_transform, import_as}
]} | [Config || {Key, _Value}=Config <- CONFIG, Key =/= deps andalso Key =/= plugins andalso Key =/= erl_opts]]
end.
80 changes: 80 additions & 0 deletions rebar.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
[{<<"aleppo">>,
{git,"https://github.com/ErlyORM/aleppo.git",
{ref,"747c18dab7c24e4674576a6b0b22e4e4ebfe84d5"}},
0},
{<<"boss_test">>,
{git,"https://github.com/ChicagoBoss/boss_test.git",
{ref,"904bdc47c87d73a891ff86b96f7a3cefd3e5c632"}},
0},
{<<"ddb">>,
{git,"https://github.com/ErlyORM/ddb.git",
{ref,"0b73869c1162da05074a5b006744ca42d4d37dbb"}},
0},
{<<"dh_date">>,
{git,"https://github.com/daleharvey/dh_date.git",
{ref,"23e5a61381d1f155520958ff28eba6a3480e9a10"}},
0},
{<<"epgsql">>,
{git,"https://github.com/epgsql/epgsql.git",
{ref,"c7dfb06481143d5554aed0d4f6853d1e3d56c670"}},
0},
{<<"erlando">>,
{git,"https://github.com/ChicagoBoss/erlando.git",
{ref,"b0b77dd9b91a0246b5b3602ccf91182e0d0a2d9a"}},
0},
{<<"erlmc">>,
{git,"https://github.com/layerhq/erlmc.git",
{ref,"abc972b27c1fbb146d03329299ef640e424b98b8"}},
0},
{<<"ets_cache">>,
{git,"https://github.com/cuongth/ets_cache.git",
{ref,"c7a17204cd9602b677540e9c73d10e6f6f7da146"}},
0},
{<<"goldrush">>,
{git,"git://github.com/DeadZen/goldrush.git",
{ref,"212299233c7e7eb63a97be2777e1c05ebaa58dbe"}},
1},
{<<"ibrowse">>,
{git,"https://github.com/cmullaparthi/ibrowse.git",
{ref,"ea3305d21f37eced4fac290f64b068e56df7de80"}},
1},
{<<"jsx">>,
{git,"https://github.com/talentdeficit/jsx.git",
{ref,"ef9818bfd2aee0a1528f1a9b13c17beb7f2471a2"}},
1},
{<<"lager">>,
{git,"https://github.com/basho/lager.git",
{ref,"1c42c3bffbab49b0f06c9a916b00ca4911ae6a2f"}},
0},
{<<"medici">>,
{git,"https://github.com/ErlyORM/medici.git",
{ref,"bb6167459d19f48089b2bd46f753bf70fce495fe"}},
0},
{<<"mysql">>,
{git,"https://github.com/ErlyORM/erlang-mysql-driver.git",
{ref,"636333c803e9132b6a2ea360b678a9f7c31623a6"}},
0},
{<<"pmod_transform">>,
{git,"git://github.com/erlang/pmod_transform.git",
{ref,"7c6fe6193b7b11c874877246bcb612414fbd1359"}},
1},
{<<"poolboy">>,
{git,"https://github.com/devinus/poolboy.git",
{ref,"3bb48a893ff5598f7c73731ac17545206d259fac"}},
0},
{<<"proper">>,
{git,"https://github.com/manopapad/proper.git",
{ref,"5f0d69c831b6c9f52535c3d1846efca480f6190d"}},
0},
{<<"redo">>,
{git,"https://github.com/heroku/redo.git",
{ref,"cd75a11697d69e38b6e5e1750b7ec18414fb60eb"}},
0},
{<<"tiny_pq">>,
{git,"https://github.com/ChicagoBoss/tiny_pq.git",
{ref,"f3d6b4d66679c1ed2670aa971715050cf00fc817"}},
0},
{<<"uuid">>,
{git,"https://github.com/avtobiff/erlang-uuid.git",
{ref,"585c2474afb4a597ae8c8bf6d21e5a9c73f18e0b"}},
0}].
Binary file modified rebar3
Binary file not shown.
29 changes: 15 additions & 14 deletions src/boss_record.erl
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
-module(boss_record).
-export([new/2, new_from_json/2]).
-include_lib("proper/include/proper.hrl").

-ifdef(TEST).
-include_lib("proper/include/proper.hrl").
-endif.

new(Model, Attributes) ->
DummyRecord = boss_record_lib:dummy_record(Model),
Expand All @@ -18,6 +20,7 @@ set_attribute(FieldName, JSON, Model) ->
BName = atom_to_binary(FieldName,'utf8'),
Model:set(FieldName, proplists:get_value(BName, JSON, null)).

-ifdef(TEST).

-spec(convert_attributes({string()|binary()|atom(), any()}) ->
{atom(), any()}).
Expand All @@ -28,18 +31,16 @@ convert_attributes({Name, Value}) when is_binary(Name) ->
convert_attributes({Name, Value}) ->
{Name, Value}.

%-ifdef(TEST).
%% unused
%% -type test_fields() :: id|name|full_name|private|html_url|description|fork|url|forks|forks_url|
%% keys_url|collaborators_url|teams_url|hooks_url|issue_events_url|events_url|
%% assignees_url|branches_url|tags_url|blobs_url|git_tags_url|git_refs_url|
%% trees_url|status_url|languages_url|star_gazers_url|commits_url|
%% git_commits_url|comments_url|issue_comment_url|contents_url|compare_url|
%% merge_url|archives_url|downloads_url|issues_url|pulls_url|milestores_url|
%% notifications_url|labels_url|releases_url|created_at|updated_at|pushed_at|
%% git_url|ssh_url|clone_url|home_page|size|stargazers_count|watchers_count|
%% language|has_issues|has_downloads|has_wiki|forks_count|mirror_url|
%% open_issues_count|forks|open_issues|watchers|default_branch|master_branch.
-type test_fields() :: id|name|full_name|private|html_url|description|fork|url|forks|forks_url|
keys_url|collaborators_url|teams_url|hooks_url|issue_events_url|events_url|
assignees_url|branches_url|tags_url|blobs_url|git_tags_url|git_refs_url|
trees_url|status_url|languages_url|star_gazers_url|commits_url|
git_commits_url|comments_url|issue_comment_url|contents_url|compare_url|
merge_url|archives_url|downloads_url|issues_url|pulls_url|milestores_url|
notifications_url|labels_url|releases_url|created_at|updated_at|pushed_at|
git_url|ssh_url|clone_url|home_page|size|stargazers_count|watchers_count|
language|has_issues|has_downloads|has_wiki|forks_count|mirror_url|
open_issues_count|forks|open_issues|watchers|default_branch|master_branch.
prop_set_attribute() ->
DummyRecord = boss_record_lib:dummy_record(gh_repo),
?FORALL({Field, Value},
Expand Down Expand Up @@ -95,4 +96,4 @@ all_true(L) ->
lists:all(fun(X) ->
X
end, L).
%-endif.
-endif.
20 changes: 10 additions & 10 deletions src/db_adapters/boss_db_adapter_pgsql.erl
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ find(Conn, Id) when is_list(Id) ->
{error, Reason}
end.

find(Conn, Type, Conditions, Max, Skip, Sort, SortOrder) when is_atom(Type),
is_list(Conditions),
is_integer(Max) orelse Max =:= all,
is_integer(Skip),
is_atom(Sort),
find(Conn, Type, Conditions, Max, Skip, Sort, SortOrder) when is_atom(Type),
is_list(Conditions),
is_integer(Max) orelse Max =:= all,
is_integer(Skip),
is_atom(Sort),
is_atom(SortOrder) ->
case boss_record_lib:ensure_loaded(Type) of
true ->
Expand All @@ -92,7 +92,7 @@ find(Conn, Type, Conditions, Max, Skip, Sort, SortOrder) when is_atom(Type),
{error, Reason} ->
{error, Reason}
end;
false ->
false ->
{error, {module_not_loaded, Type}}
end.

Expand Down Expand Up @@ -279,9 +279,9 @@ build_insert_query(Record) ->
build_insert_sql(TableName, Attributes, Values, Params).


-spec(build_insert_sql(nonempty_string(),
[nonempty_string(),...],
[sql_param_value(),...],
-spec(build_insert_sql(nonempty_string(),
[nonempty_string(),...],
[sql_param_value(),...],
[nonempty_string(),...]) ->
{iolist(), [sql_param_value()]}).
build_insert_sql(TableName, Attributes, Values, Params) ->
Expand Down Expand Up @@ -309,7 +309,7 @@ make_insert_attributes(Record, Type) ->
({A, V}, {Attrs, Vals}) ->
DBColumn = proplists:get_value(A, AttributeColumns),
Value = make_value(Type, A, V),
{[DBColumn|Attrs],
{[DBColumn|Attrs],
[Value|Vals]}
end, {[], []}, Record:attributes()).

Expand Down
4 changes: 4 additions & 0 deletions src/prop_runner.erl
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
-module(prop_runner).

-ifdef(TEST).
-include_lib("proper/include/proper.hrl").
-include_lib("eunit/include/eunit.hrl").

Expand All @@ -21,3 +23,5 @@ gen(Tests, TModule,Count,PCount) ->
[{to_file, user},Count]))
end||Test <-Tests]
end}.

-endif.

0 comments on commit 35c6209

Please sign in to comment.