api.hrl 2.0 KB

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