Starting DB implementation.

Added Makefile, id_counter.erl, and yaws.conf.
Created ts_common module. Will contain common DB code. So far only list/3.
Created ts_timeline module. DB code for storing timeline entries.
Created ts_entry module, DB code for storing timelin entries.
This commit is contained in:
Jonathan Bernard
2011-01-28 06:49:47 -06:00
parent 111da51c73
commit 495336fc58
7 changed files with 165 additions and 0 deletions

19
src/ts_entry.erl Normal file
View File

@ -0,0 +1,19 @@
-module(ts_entry).
-export([create_table/1, new/1, update/1, list/3]).
-include("ts_db_records.hrl").
-include_lib("stdlib/include/qlc.hrl").
create_table(TableOpts) ->
mnesia:create_table(ts_entry,
TableOpts ++ [{attributes, record_info(fields, ts_entry)},
{type, ordered_set}, {index, timestamp}]).
new(ER = #ts_entry()) ->
{atmoic, NewRow) = mnesia:transaction(fun() ->
{Username, TimelineId, _} = ER#ts_entry.ref,
NextId = id_counter:next_counter(ts_entry_id),
NewRow = ER#ts_entry{ref = {Username, TimelineId, NextId}},
ok = mnesia:write(NewRow),
NewRow end),
{ok, NewRow}.