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:
19
src/ts_entry.erl
Normal file
19
src/ts_entry.erl
Normal 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}.
|
Reference in New Issue
Block a user