Packages
kvs
2.1.0
13.5.22-aleph
13.4.16
13.4.15
13.4.14
13.4.13
13.3.1
13.2.28
11.9.1
10.8.3
10.8.2
10.3.0
9.9.2
9.9.1
9.9.0
9.8.0
9.7.0
9.4.8
9.4.7
9.4.6
9.4.5
9.4.4
9.4.3
9.4.2
9.4.1
9.4.0
8.12.0
8.11.2
8.11.1
8.10.4
8.10.3
8.10.2
8.10.1
8.10.0
8.5.2
8.5.1
8.5.0
8.4.1
8.4.0
8.3.1
8.3.0
7.11.5
7.9.1
7.7.0
7.1.3
7.1.2
7.1.1
6.12.11
6.12.10
6.12.9
6.12.8
6.12.7
6.12.6
6.12.5
6.12.4
6.12.3
6.12.2
6.12.1
6.12.0
6.11.2
6.11.1
6.11.0
6.10.2
6.10.1
6.10.0
6.9.2
6.9.1
6.9.0
6.7.7
6.7.6
6.7.5
6.7.4
6.7.3
6.7.2
6.7.1
6.7.0
6.6.0
2.1.0
0.12.1
retired
KVS Key-Value Store Abstraction Layer
Current section
Files
Jump to
Current section
Files
src/store_fs.erl
-module(store_fs).
-copyright('Synrc Research Center s.r.o.').
-include("config.hrl").
-include("metainfo.hrl").
-include_lib("stdlib/include/qlc.hrl").
-compile(export_all).
start() -> ok.
stop() -> ok.
destroy() -> ok.
version() -> {version,"KVS FS"}.
dir() -> filelib:fold_files("data", "",true, fun(A,Acc)-> [{table,A}|Acc] end, []).
join() -> ensure_dir("data").
join(Node) -> ok. % should be rsync or smth
change_storage(Table,Type) -> ok.
initialize() ->
kvs:info(?MODULE,"[store_mnesia] mnesia init.~n",[]),
mnesia:create_schema([node()]),
[ kvs:init(store_fs,Module) || Module <- kvs:modules() ],
mnesia:wait_for_tables([ T#table.name || T <- kvs:tables()],infinity).
index(Tab,Key,Value) ->
Table = kvs:table(Tab),
Index = string:str(Table#table.fields,[Key]),
lists:flatten(many(fun() -> mnesia:index_read(Tab,Value,Index+1) end)).
get(RecordName, Key) -> just_one(fun() -> mnesia:read(RecordName, Key) end).
put(Records) when is_list(Records) -> void(fun() -> lists:foreach(fun mnesia:write/1, Records) end);
put(Record) -> put([Record]).
delete(Tab, Key) ->
case mnesia:transaction(fun()-> mnesia:delete({Tab, Key}) end) of
{aborted,Reason} -> {error,Reason};
{atomic,_Result} -> ok end.
count(RecordName) -> length(filelib:fold_files(lists:concat(["data/",RecordName]), "",true, fun(A,Acc)-> [A|Acc] end, [])).
all(R) -> filelib:fold_files(lists:concat(["data/",RecordName]), "",true, fun(A,Acc)-> [A|Acc] end, []).
next_id(RecordName, Incr) -> mnesia:dirty_update_counter({id_seq, RecordName}, Incr).
create_table(Name,Options) ->
X = mnesia:create_table(Name, Options),
kvs:info("Create table ~p ~nOptions ~p~nReturn ~p~n",[Name, Options,X]),
X.
add_table_index(Record, Field) -> mnesia:add_table_index(Record, Field).
exec(Q) -> F = fun() -> qlc:e(Q) end, {atomic, Val} = mnesia:transaction(F), Val.
just_one(Fun) ->
case mnesia:transaction(Fun) of
{atomic, []} -> {error, not_found};
{atomic, [R]} -> {ok, R};
{atomic, [_|_]} -> {error, duplicated};
Error -> Error end.