[938994]: src / erl / lib / libdb.erl Maximize Restore History

Download this file

libdb.erl    62 lines (52 with data), 2.1 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
-module(libdb).
-export([create/0, sequence/1, clear/0, write/1, read/1]).
-include("schema.hrl").
-include_lib("stdlib/include/qlc.hrl").
-record(sequence, {key, index}).
%%
create()->
mnesia:create_table(file,[{disc_copies, [node()]},{attributes, record_info(fields, file)}]),
mnesia:create_table(media,[{disc_copies, [node()]},{attributes, record_info(fields, media)}]),
mnesia:create_table(watchfolder,[{disc_copies, [node()]},{attributes, record_info(fields, watchfolder)}]),
mnesia:create_table(stream,[{disc_copies, [node()]},{attributes, record_info(fields, stream)}]),
mnesia:create_table(profile,[{disc_copies, [node()]},{attributes, record_info(fields, profile)}]),
mnesia:create_table(job,[{disc_copies, [node()]},{attributes, record_info(fields, job)}]),
mnesia:create_table(jobdetail,[{disc_copies, [node()]},{attributes, record_info(fields, jobdetail)}]),
mnesia:create_table(process_unit,[{disc_copies, [node()]},{attributes, record_info(fields, process_unit)}]),
mnesia:create_table(packet,[{disc_copies, [node()]},{attributes, record_info(fields, packet)}]),
mnesia:create_table(config,[{disc_copies, [node()]},{attributes, record_info(fields, config)}]),
mnesia:create_table(sequence, [{type, set}, {disc_copies,[node()]}, {attributes, record_info(fields, sequence)}]).
drop()->
mnesia:delete_table(file),
mnesia:delete_table(media),
mnesia:delete_table(watchfolder),
mnesia:delete_table(stream),
mnesia:delete_table(profile),
mnesia:delete_table(job),
mnesia:delete_table(jobdetail),
mnesia:delete_table(process_unit),
mnesia:delete_table(packet),
mnesia:delete_table(config),
mnesia:delete_table(sequence).
load()->
mnesia:load_textfile("test.data").
clear()->
drop(),
create(),
load().
sequence(Name, Inc) ->
mnesia:dirty_update_counter(sequence, Name, Inc).
sequence(Name) ->
sequence(Name, 1).
write(Obj)->
case mnesia:transaction(fun() ->mnesia:write(Obj)end) of
{atomic, ok} ->
ok;
Err->{error, Err}
end.
read(Table)->
F=fun()->
qlc:e(qlc:q([Data||Data<-mnesia:table(Table)]))
end,
{atomic,Data}=mnesia:transaction(F),
Data.