Permalink
Browse files

Merge pull request #1 from maruthavanan/master

Rebarized & Record attribute modifications
  • Loading branch information...
2 parents 6610b73 + efcd5ed commit b07fce86688cb5dc1c1832a724d7706bbd66b5e2 Bruno Pedro committed Jan 9, 2013
Showing with 25 additions and 69 deletions.
  1. +0 −20 Makefile
  2. +3 −3 README.md
  3. +3 −0 rebar.config
  4. +0 −33 src/Makefile
  5. 0 src/{webnesia.app → webnesia.app.src}
  6. +5 −5 src/webnesia_db.erl
  7. +14 −8 src/webnesia_response.erl
View
@@ -1,20 +0,0 @@
-all: ebin/
- (cd src;$(MAKE) all)
-
-edoc:
- (cd src;$(MAKE) edoc)
-
-test:
- (cd src;$(MAKE) test)
-
-clean:
- (cd src;$(MAKE) clean)
-
-clean_plt:
- (cd src;$(MAKE) clean_plt)
-
-dialyzer:
- (cd src;$(MAKE) dialyzer)
-
-ebin/:
- @mkdir -p ebin
View
@@ -6,11 +6,11 @@ webnesia is a REST interface to Erlang's mnesia. It provides an API and a Web fr
## Installation instructions
-1. make sure you have [mochiweb](https://github.com/mochi/mochiweb) installed;
+1. Make sure you have added rebar in $PATH
-2. check the symlink to mochiweb source on `deps/`;
+2. Webnesia depends on mochiweb. To download dependencies `rebar get-deps`
-3. run `make`;
+3. To compile `rebar compile`
4. run `./start-dev.sh`;
View
@@ -0,0 +1,3 @@
+{deps, [
+ {mochiweb,".*", {git, "git://github.com/mochi/mochiweb.git", "master"}}
+ ]}.
View
@@ -1,33 +0,0 @@
-include ../support/include.mk
-
-APPLICATION=webnesia
-DOC_OPTS={dir,\"../doc\"}
-TEST_PLT=$(TEST_DIR)/dialyzer_plt
-
-all: $(EBIN_FILES)
-
-debug:
- $(MAKE) DEBUG=-DDEBUG
-
-clean:
- rm -rf $(EBIN_FILES)
-
-edoc:
- $(ERL) -noshell -pa ../ebin \
- -eval "edoc:application($(APPLICATION), \".\", [$(DOC_OPTS)])" \
- -s init stop
-
-test: $(EBIN_FILES)
- mkdir -p $(TEST_DIR);
- @../support/run_tests.escript $(EBIN_DIR) | tee $(TEST_DIR)/test.log
-
-$(TEST_PLT):
- mkdir -p $(TEST_DIR)
- cp $(DIALYZER_PLT) $(TEST_PLT)
- dialyzer --plt $(TEST_PLT) --add_to_plt -r ../deps/*/ebin
-
-clean_plt:
- rm $(TEST_PLT)
-
-dialyzer: $(TEST_PLT)
- dialyzer --src --plt $(TEST_PLT) -DNOTEST -DDIALYZER -c ../src | tee $(TEST_DIR)/dialyzer.log
File renamed without changes.
View
@@ -100,7 +100,7 @@ list (Table, Limit, 0) ->
%%--------------------------------------------------------------------
list (Table, Limit, Offset) ->
{atomic, Records} = mnesia:transaction(fun() -> C = qlc:cursor(qlc:q([X||X<-mnesia:table(list_to_atom(Table))])), qlc:next_answers(C, Offset), qlc:next_answers(C, Limit) end ),
- webnesia_response:encode_records(Records, mnesia:table_info(list_to_atom(Table), size), Limit, Offset).
+ webnesia_response:encode_records(Records,list_to_atom(Table), Limit, Offset).
%--------------------------------------------------------------------
%% @doc
@@ -117,7 +117,7 @@ list (Table, 0) ->
%%--------------------------------------------------------------------
list (Table, Limit) ->
{atomic, Records} = mnesia:transaction(fun() -> C = qlc:cursor(qlc:q([X||X<-mnesia:table(list_to_atom(Table))])), qlc:next_answers(C, Limit) end ),
- webnesia_response:encode_records(Records, mnesia:table_info(list_to_atom(Table), size), Limit, 0).
+ webnesia_response:encode_records(Records, list_to_atom(Table), Limit, 0).
%--------------------------------------------------------------------
%% @doc
@@ -126,7 +126,7 @@ list (Table, Limit) ->
%%--------------------------------------------------------------------
list (Table) ->
{atomic, Records} = mnesia:transaction(fun() -> mnesia:match_object(list_to_atom(Table), mnesia:table_info(list_to_atom(Table), wild_pattern), write) end),
- webnesia_response:encode_records(Records, mnesia:table_info(list_to_atom(Table), size), mnesia:table_info(list_to_atom(Table), size), 0).
+ webnesia_response:encode_records(Records, list_to_atom(Table), mnesia:table_info(list_to_atom(Table), size), 0).
%--------------------------------------------------------------------
%% @doc
@@ -151,7 +151,7 @@ save (Table, JSONData) ->
%%--------------------------------------------------------------------
read (Table, Key) ->
{atomic, Records} = mnesia:transaction(fun() -> mnesia:read(list_to_atom(Table), mochijson2:decode(Key)) end),
- webnesia_response:encode_records(Records, mnesia:table_info(list_to_atom(Table), size), mnesia:table_info(list_to_atom(Table), size), 0).
+ webnesia_response:encode_records(Records, list_to_atom(Table), mnesia:table_info(list_to_atom(Table), size), 0).
%--------------------------------------------------------------------
%% @doc
@@ -184,4 +184,4 @@ create_table_test () ->
delete_table_test () ->
?assert(webnesia_db:delete_table("test_table") =:= [34, "ok", 34]).
--endif.
+-endif.
View
@@ -22,15 +22,15 @@ encode (Data) ->
%%
%% @end
%%--------------------------------------------------------------------
-encode_records (Records, Size, Limit, Offset) ->
- encode({struct, [{total_rows, Size}, {number_of_rows, length(Records)}, {limit, Limit}, {offset, Offset}, {rows, records_to_structs(Records)}]}).
+encode_records (Records, Table, Limit, Offset) ->
+ encode({struct, [{total_rows, mnesia:table_info(Table, size)}, {number_of_rows, length(Records)}, {limit, Limit}, {offset, Offset}, {rows, records_to_structs(mnesia:table_info(Table, attributes), Records)}]}).
%--------------------------------------------------------------------
%% @doc
%%
%% @end
%%--------------------------------------------------------------------
-records_to_structs ([]) ->
+records_to_structs (_, []) ->
[];
%--------------------------------------------------------------------
@@ -40,8 +40,14 @@ records_to_structs ([]) ->
%%
%% @end
%%--------------------------------------------------------------------
-records_to_structs ([Record | Tail]) ->
- [Table | Values] = tuple_to_list(Record),
- Attributes = mnesia:table_info(Table, attributes),
- lists:merge(fun(_, _) -> true end, [{struct, lists:zip(Attributes, Values)}], records_to_structs(Tail)).
-
+records_to_structs (Attributes, [Record | Tail]) ->
+ [_ | Values] = tuple_to_list(Record),
+ NewValues = change_binary(Values,[]), %% if the content is in list it is changed to binary so that id displays correctly at frontend.
+ lists:merge(fun(_, _) -> true end, [{struct, lists:zip(Attributes, NewValues)}], records_to_structs(Attributes, Tail)).
+
+change_binary([], Acc)->
+ Acc;
+change_binary([H|T], Acc) when is_list(H) ->
+ change_binary(T,Acc++[list_to_binary(H)]);
+change_binary([H|T], Acc) -> change_binary(T,Acc++[H]).
+

0 comments on commit b07fce8

Please sign in to comment.