api.hrl 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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,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}.
  29. -spec remove(Tab :: atom(), Key :: any()) -> ok | {error,any()}.
  30. % raw ops
  31. -spec put(Record :: tuple()) -> ok | {error,any()}.
  32. -spec delete(Tab :: atom(), Key :: any()) -> ok | {error,any()}.
  33. % read ops
  34. -spec get(Tab :: atom(), Key :: any()) -> {ok,any()} | {error,duplicated} | {error,not_found}.
  35. -spec get(Tab :: atom(), Key :: any(), Value :: any()) -> {ok,any()}.
  36. -spec index(Tab :: atom(), Key :: any(), Value :: any()) -> list(tuple()).
  37. % import/export
  38. -spec load_db(Path :: string()) -> list(ok | {error,any()}).
  39. -spec save_db(Path :: string()) -> ok | {error,any()}.
  40. -endif.