kvs.htm 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <!DOCTYPE html><html><head><meta charset="utf-8" />
  2. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  3. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  4. <meta name="description" content="" /><meta name="author" content="Maxim Sokhatsky" />
  5. <title>KVS</title>
  6. <link rel="stylesheet" href="https://n2o.dev/blank.css" />
  7. <link rel="stylesheet" href="https://n2o.dev/zima.css" />
  8. </head><body><nav>
  9. <a href="https://n2o.dev">DEV</a>
  10. <a href="https://kvs.n2o.dev">KVS</a>
  11. <a href="#" style="background:#ededed;">API</a>
  12. <div class="dropdown">
  13. <a onclick="drop()" class="dropbtn">EN</a>
  14. <div id="dropdown" class="dropdown-content">
  15. <a href="https://n2o.dev/deps/kvs/man/ua/kvs.htm">UA</a>
  16. <a href="#">EN</a>
  17. </div>
  18. </div>
  19. </nav><header>
  20. <a href="../index.html"><img src="https://openmoji.org/data/color/svg/1F4BF.svg"/></a>
  21. <h1>KVS</h1>
  22. </header>
  23. <main>
  24. <article>
  25. <section>
  26. <h3>INTRO</h3>
  27. <p>KVS module provides user level interface for console commands.
  28. It has discovery, data manipulation and retrival features. Under the hood
  29. it handles configurable run-time backends for each supported database.</p>
  30. <blockquote>
  31. <ul><li><b><a href="#put">put/1</a></b> — put record using id as a key.</li>
  32. <li><b><a href="#get">get/2</a></b> — get record by key from table.</li>
  33. <li><b><a href="#delete">delete/1</a></b> — delete record from table.</li>
  34. <li><b><a href="#index">index/3</a></b> — search records by field and its value.</li>
  35. <li><b><a href="#seq">seq/2</a></b> — generate new sequence table id.</li>
  36. <li><b><a href="#count">count/1</a></b> — counts records in table.</li>
  37. <li><b><a href="#dir">dir/0</a></b> — table list.</li>
  38. </ul></blockquote>
  39. <p>You can change backend by setting application env.
  40. This behaves well even under the heavy load.</p>
  41. </section>
  42. <section>
  43. <h3>API</h3>
  44. <p>Data operations.</p>
  45. <h4 id="put">put(tuple()) -> ok | {error,any()}.</h4>
  46. <p>Stores the record.</p>
  47. <h4 id="get">get(atom(),any()) -> {ok,any()} | {error, not_found | duplicated }.</h4>
  48. <p>Retrieves the record.</p>
  49. <h4 id="delete">delete(atom(),any()) -> ok | {error,any()}.</h4>
  50. <p>Deletes the data record.</p>
  51. <h4 id="index">index(atom(),any(),any()) -> list(tuple()).</h4>
  52. <p>Searches the record by an indexed field and a given value.</p>
  53. </section>
  54. <section>
  55. <h3>SEQ</h3>
  56. <p>Sequence table id_seq stores the counter per thing.
  57. The couners are global and atomic in each supported database.
  58. Sequences are used to generate unique names for records per distributed table.
  59. If names in the table are not unique, e.g.
  60. then count function may return a different value than the current sequence.</p>
  61. <figure><code> -record(id_seq, { thing = atom(),
  62. id = 0 :: integer() } ).</code></figure>
  63. <h4 id="seq">seq(atom(), integer()) -> integer().</h4>
  64. <p>Increments and returns id counter for the particular table.</p>
  65. <h4 id="count">count(atom()) -> integer().</h4>
  66. <p>Returns number of records in table.</p>
  67. </section>
  68. <section>
  69. <h3>SETUP</h3>
  70. <p>In <b>sys.config</b> you can specify main kvs backend module as <b>dba</b> parameter
  71. and list of modules containing <b>metainfo/0</b> exported function. For the
  72. stream operations you can specify the stream kvs backend module <b>dba_st</b> parameter.</p>
  73. <figure><code> [{kvs, [{dba,store_mnesia},
  74. {dba_st,store_stream},
  75. {schema,[kvs,kvs_stream]}]}].</code></figure>
  76. <h4 id="dir">dir() -> list({'table',atom()}).</h4>
  77. <p>Returns actual tables.</p>
  78. </section>
  79. <section>
  80. <p>This module may refer to:
  81. <a href="kvs_fs.htm">kvs_fs</a>,
  82. <a href="kvs_mnesia.htm">kvs_mnesia</a>,
  83. <a href="kvs_rocks.htm">kvs_rocks</a>,
  84. <a href="kvs_st.htm">kvs_st</a>,
  85. <a href="kvs_stream.htm">kvs_stream</a>.
  86. </p>
  87. </section>
  88. </article>
  89. </main>
  90. <footer>2005—2019 © Synrc Research Center</footer>
  91. <script>function drop(){document.getElementById("dropdown").classList.toggle("show");}</script>
  92. </body>
  93. </html>