api.hrl 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. -include("metainfo.hrl").
  2. % exports
  3. -export([start/0,stop/0]). % service
  4. -export([destroy/0,join/0,join/1,init/2]). % schema change
  5. -export([modules/0,containers/0,tables/0,table/1,version/0]). % meta info
  6. -export([create/1,add/1,link/1,remove/2]). % chain ops
  7. -export([put/1,delete/2,next_id/2]). % raw ops
  8. -export([get/2,get/3,index/3]). % read ops
  9. -export([load_db/1,save_db/1]). % import/export
  10. % service
  11. -spec start() -> ok | {error,any()}.
  12. -spec stop() -> stopped.
  13. % schema change
  14. -spec destroy() -> ok.
  15. -spec join() -> ok | {error,any()}.
  16. -spec join(Node :: string()) -> [{atom(),any()}].
  17. -spec init(Backend :: atom(), Module :: atom()) -> list(#table{}).
  18. % meta info
  19. -spec modules() -> list(atom()).
  20. -spec containers() -> list(tuple(atom(),list(atom()))).
  21. -spec tables() -> list(#table{}).
  22. -spec table(Tab :: atom()) -> #table{}.
  23. -spec version() -> {version,string()}.
  24. % chain ops
  25. -spec create(Container :: atom()) -> integer().
  26. -spec add(Record :: tuple()) -> {ok,tuple()} | {error,exist} | {error,no_container}.
  27. -spec remove(Tab :: atom(), Key :: any()) -> ok | {error,any()}.
  28. % raw ops
  29. -spec put(Record :: tuple()) -> ok | {error,any()}.
  30. -spec delete(Tab :: atom(), Key :: any()) -> ok | {error,any()}.
  31. % read ops
  32. -spec get(Tab :: atom(), Key :: any()) -> {ok,any()} | {error,duplicated} | {error,not_found}.
  33. -spec get(Tab :: atom(), Key :: any(), Value :: any()) -> {ok,any()}.
  34. -spec index(Tab :: atom(), Key :: any(), Value :: any()) -> list(tuple()).
  35. % import/export
  36. -spec load_db(Path :: string()) -> list(ok | {error,any()}).
  37. -spec save_db(Path :: string()) -> ok | {error,any()}.