kvs.htm 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  7. <meta name="description" content="" />
  8. <meta name="author" content="Maxim Sokhatsky" />
  9. <title>KVS</title>
  10. <link rel="stylesheet" href="https://synrc.space/synrc.css" />
  11. </head>
  12. <body>
  13. <nav>
  14. <a href='https://n2o.dev'>DEV</a>
  15. <a href='https://kvx.n2o.space'>KVS</a>
  16. <a href='#' style="background:#ededed;">KVS</a>
  17. </nav>
  18. <header>
  19. <a href="../index.html"><img src="https://n2o.space/img/Synrc Neo.svg"></a>
  20. <h1>KVS</h1>
  21. </header>
  22. <main>
  23. <section>
  24. <h3>INTRO</h3>
  25. <p>KVS module provides user level interface for console commands.
  26. It has discovery, data manipulation and retrival features. Under the hood
  27. it handles configurable run-time backends for each supported database.</p>
  28. <p><blockquote><p><ul>
  29. <li><b><a href="#dir">dir/0</a></b> &mdash; table list.</li>
  30. <li><b><a href="#ver">ver/0</a></b> &mdash; KVS version.</li>
  31. <li><b><a href="#seq">seq/2</a></b> &mdash; generate new sequence table id.</li>
  32. <li><b><a href="#count">count/1</a></b> &mdash; counts records in table.</li>
  33. <li><b><a href="#put">put/1</a></b> &mdash; put record using id as a key.</li>
  34. <li><b><a href="#get">get/2</a></b> &mdash; get record by key from table.</li>
  35. <li><b><a href="#delete">delete/1</a></b> &mdash; delete record from table.</li>
  36. <li><b><a href="#index">index/3</a></b> &mdash; search records by field and its value.</li>
  37. </ul></p></blockquote></p>
  38. <p>You can change backend by setting application env.
  39. This behaves well even under the heavy load.</p>
  40. </section>
  41. <section>
  42. <h3>SETUP</h3>
  43. <p>In sys.config you should specify kvx backend and list of modules
  44. containing <b>metainfo/0</b> exported function.</p>
  45. <figure><code>
  46. [{kvx, [{dba,store_mnesia},
  47. {schema,[kvx,kvx_stream]}]}].
  48. </code></figure>
  49. <h4>dir() -> list({'table',atom()}).</h4>
  50. <p>Returns actual tables.</p>
  51. <h4>ver() -> {'version',string()}.</h4>
  52. <p>Returns backend version.</p>
  53. <h4>dump() -> ok.</h4>
  54. <p>Display database information.</p>
  55. <figure><code>
  56. > kvx:dump().
  57. NAME STORAGE TYPE MEMORY (MB) ELEMENTS
  58. id_seq disc_copies 0.00 0
  59. writer disc_copies 0.00 0
  60. emails disc_copies 0.00 0
  61. reader disc_copies 0.00 0
  62. Snapshot taken: {{2018,11,10},{5,2,38}}
  63. ok
  64. </code></figure>
  65. </section>
  66. <section>
  67. <h3>SEQ</h3>
  68. <p>Sequence table id_seq stores the counter per thing.
  69. The couners are global and atomic in each supported database.
  70. Sequences are used to generate unique names for records per distributed table.
  71. If names in the table are not unique, e.g.
  72. then count function may return a different value than the current sequence.
  73. </p>
  74. <figure><code>
  75. -record(id_seq, { thing = atom(),
  76. id = 0 :: integer() } ).
  77. </code></figure>
  78. <h4>seq(atom(), integer()) -> integer().</h4>
  79. <p>Increments and returns id counter for the particular table.</p>
  80. <h4>count(atom()) -> integer().</h4>
  81. <p>Returns number of records in table.</p>
  82. </section>
  83. <section>
  84. <h3>BACKEND</h3>
  85. <p>Data operations.
  86. </p>
  87. <h4>put(tuple()) -> ok | {error,any()}.</h4>
  88. <p>Storing of data record.</p>
  89. <h4>get(atom(),any()) -> {ok,any()} | {error, not_found | duplicated }.</h4>
  90. <p>Retrieval of data record.</p>
  91. <h4>delete(atom(),any()) -> ok | {error,any()}.</h4>
  92. <p>Deletion of data record.</p>
  93. <h4>index(atom(),any(),any()) -> list(tuple()).</h4>
  94. <p>Search of data record by an indexed field and a given value.</p>
  95. </section>
  96. <section>
  97. <p>This module may refer to:
  98. <a href="kvx_fs.htm"><b>kvx_fs</b></a>,
  99. <a href="kvx_mnesia.htm"><b>kvx_mnesia</b></a>,
  100. <a href="kvx_rocks.htm"><b>kvx_rocks</b></a>,
  101. <a href="kvx_st.htm"><b>kvx_st</b></a>,
  102. <a href="kvx_stream.htm"><b>kvx_stream</b></a>.
  103. </p>
  104. </section>
  105. </main>
  106. <footer>
  107. 2005&mdash;2019 &copy; Synrc Research Center
  108. </footer>
  109. </body>
  110. </html>