-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
120 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,79 +4,90 @@ | |
|
||
%% Main entry point. | ||
main(_) -> | ||
setup_codepath(), | ||
start_apps(), | ||
setup_codepath(), | ||
start_apps(), | ||
|
||
%% Install our event manager and register our handlers (not mandatory). | ||
{ok, _EventManagerPid} = gen_event:start({local, my_event_bus}), | ||
gen_event:add_handler(my_event_bus, blog_event_handler, []), | ||
|
||
%% Let's first create our db schema. Database should be already created. All | ||
%% other schemas are auto generated. | ||
ok = sumo:create_schema(), | ||
|
||
%% Cleanup authors and posts, so we can have a fresh runup. | ||
_NumRows1 = blog:del_author(), | ||
_NumRows2 = blog:del_post(), | ||
_NumRows3 = blog:del_reader(), | ||
_NumRows3 = blog:del_vote(), | ||
|
||
%% Let's create a new blog author and a new blog entry. The result is the | ||
%% same author and post with their new id's filled in. | ||
Author = blog:new_author(<<"Pepe Gorostiga">>, <<"some binary jpg">>), | ||
Post = blog:new_post(<<"How awesome sumo_db is">>, | ||
<<"It just make things easy">>, | ||
Author), | ||
|
||
%% Let's now delete them. | ||
true = blog:del_post(Post), | ||
true = blog:del_author(Author), | ||
|
||
%% Let's create them again | ||
Author2 = blog:new_author(<<"Pepe Gorostiga">>, <<"some binary jpg">>), | ||
_Author3 = blog:new_author(<<"Some other guy">>, <<"some other photo">>), | ||
Post2 = blog:new_post(<<"How awesome sumo_db is">>, | ||
<<"It just make things easy">>, | ||
Author2), | ||
|
||
timer:sleep(1000), | ||
|
||
%% Update author and post. | ||
blog:save_author(blog_author:update_photo(<<"new photo">>, Author2)), | ||
blog:save_post(blog_post:update_title("My new shiny title", Post2)), | ||
|
||
io:format("Authors by name: ~p~n", | ||
[blog:find_authors_by_name(<<"Pepe Gorostiga">>, 0, 0)]), | ||
io:format("Authors: ~p~n", [blog:find_all_authors(10, 0)]), | ||
io:format("A blog: ~p~n", [blog:find_post(blog_post:id(Post2))]), | ||
io:format("An author: ~p~n", [blog:find_author(blog_author:id(Author2))]), | ||
|
||
%% Call a specific method of a repo (not handled by the generic repo, | ||
%% i.e: a "complex" work). | ||
%% io:format("Total number of posts: ~p~n", [blog:total_posts()]), | ||
|
||
%% Create a blog reader, in a nother repo and backend. | ||
Reader = blog:new_reader("Marcelo Gornstein", "[email protected]"), | ||
Reader2 = blog:new_reader("Pepe Gorostiga", "[email protected]"), | ||
|
||
timer:sleep(1000), | ||
|
||
io:format("A Reader: ~p~n", [blog:find_reader(blog_reader:id(Reader))]), | ||
blog:save_reader(blog_reader:update_email("[email protected]", Reader)), | ||
blog:save_reader(blog_reader:update_email("[email protected]", Reader2)), | ||
io:format("Another Reader: ~p~n", | ||
[blog:find_reader(blog_reader:id(Reader))]), | ||
|
||
%% Create a vote | ||
_Vote = blog:new_vote(blog_reader:id(Reader2), blog_post:id(Post2)), | ||
|
||
io:format("Deleted ~p authors~n", | ||
[blog:del_author_by_name("Pepe Gorostiga")]). | ||
|
||
% Install our event manager and register our handlers (not mandatory). | ||
{ok, _EventManagerPid} = gen_event:start({local, my_event_bus}), | ||
gen_event:add_handler(my_event_bus, blog_event_handler, []), | ||
|
||
% Let's first create our db schema. Database should be already created. All | ||
% other schemas are auto generated. | ||
ok = sumo:create_schema(), | ||
|
||
% Cleanup authors and posts, so we can have a fresh runup. | ||
_NumRows1 = blog:del_author(), | ||
_NumRows2 = blog:del_post(), | ||
_NumRows3 = blog:del_reader(), | ||
|
||
% Let's create a new blog author and a new blog entry. The result is the | ||
% same author and post with their new id's filled in. | ||
Author = blog:new_author("Pepe Gorostiga", <<"some binary jpg">>), | ||
Post = blog:new_post("How awesome sumo_db is", "It just make things easy", Author), | ||
|
||
% Let's now delete them. | ||
true = blog:del_post(Post), | ||
true = blog:del_author(Author), | ||
|
||
% Let's create them again | ||
Author2 = blog:new_author("Pepe Gorostiga", <<"some binary jpg">>), | ||
Author3 = blog:new_author("Some other guy", <<"some other photo">>), | ||
Post2 = blog:new_post("How awesome sumo_db is", "It just make things easy", Author2), | ||
|
||
% Update author and post. | ||
blog:save_author(blog_author:update_photo(<<"new photo">>, Author2)), | ||
blog:save_post(blog_post:update_title("My new shiny title", Post2)), | ||
|
||
io:format("Authors by name: ~p~n", [blog:find_authors_by_name("Pepe Gorostiga", 10, 0)]), | ||
io:format("Authors: ~p~n", [blog:find_all_authors(10, 0)]), | ||
io:format("A blog: ~p~n", [blog:find_post(blog_post:id(Post2))]), | ||
io:format("An author: ~p~n", [blog:find_author(blog_author:id(Author2))]), | ||
|
||
% Call a specific method of a repo (not handled by the generic repo, | ||
% i.e: a "complex" work). | ||
% io:format("Total number of posts: ~p~n", [blog:total_posts()]), | ||
|
||
% Create a blog reader, in a nother repo and backend. | ||
Reader = blog:new_reader("Marcelo Gornstein", "[email protected]"), | ||
Reader2 = blog:new_reader("Pepe Gorostiga", "[email protected]"), | ||
io:format("A Reader: ~p~n", [blog:find_reader(blog_reader:id(Reader))]), | ||
|
||
blog:save_reader(blog_reader:update_email("[email protected]", Reader)), | ||
blog:save_reader(blog_reader:update_email("[email protected]", Reader2)), | ||
io:format("Another Reader: ~p~n", [blog:find_reader(blog_reader:id(Reader))]), | ||
|
||
% Create a vote | ||
_Vote = blog:new_vote(blog_reader:id(Reader2), blog_post:id(Post2)), | ||
setup_codepath() -> | ||
Dir = filename:dirname(escript:script_name()), | ||
|
||
io:format("Deleted ~p authors~n", [blog:del_author_by_name("Pepe Gorostiga")]). | ||
DepsDirs = filelib:wildcard(Dir ++ "/../../deps/*"), | ||
|
||
setup_codepath() -> | ||
Dir = filename:dirname(escript:script_name()), | ||
Deps = [ | ||
"lager", "goldrush", "worker_pool", "emysql", "emongo", | ||
"sqlite3" | ||
], | ||
DepsDir = filename:absname(Dir ++ "/../../deps/"), | ||
code:add_patha(filename:absname(Dir ++ "/../../ebin")), | ||
[ code:add_patha(DepsDir ++ "/" ++ X ++ "/ebin") || X <- Deps]. | ||
code:add_patha(filename:absname(Dir ++ "/../../ebin")), | ||
code:add_patha(filename:absname(Dir ++ "/ebin")), | ||
[code:add_patha(X ++ "/ebin") || X <- DepsDirs]. | ||
|
||
start_apps() -> | ||
application:ensure_all_started(tirerl), | ||
|
||
application:ensure_all_started(goldrush), | ||
Apps = [ | ||
sasl, compiler, syntax_tools, lager, crypto, | ||
emysql, emongo, sqlite3, worker_pool, | ||
sumo_db | ||
], | ||
[ ok = application:start(X) || X <- Apps]. | ||
[ application:start(X) || X <- Apps ]. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters