123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- <html>
- <head>
- <meta charset="utf-8" />
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
- <meta name="description" content="" />
- <meta name="author" content="Maxim Sokhatsky" />
- <title>STREAM</title>
- <link rel="stylesheet" href="https://n2o.space/n2o.css" />
- </head>
- <body>
- <header>
- <a href="../index.html"><img src="https://n2o.space/img/Synrc Neo.svg"></a>
- <h1>STREAM</h1>
- </header>
- <main>
- <section>
- <h3>INTRO</h3>
- <p>The <b>kvs_stream</b> is intended to store and retrieve doubly-linked lists using
- simple key-value access to different databases through its backends:
- redis, mongo, mnesia, riak, kai, fs.
- The main descriptor of the list is the cursor which holds the cached value of one of list elements
- and also two pointers to first and last elements along with default traversal direction.
- Cursor should be stored in databse, if there is no cursor for some data then this data is not alive yet.
- The data could be added only from list ends.
- The data in list could be removed by record id.
- The list could not contain duplicates or even records with the same id.
- When you consume the stream, the data is not deleted, you need to remove it manually.</p>
- </section>
- <section>
- <h3>RECORDS</h3>
- <figure><figcaption>KVS CORE</figcaption><code>
- #ok { data= [] :: term() }.
- #error { data= [] :: term() }.
- #cur { id= [] :: term(),
- val= [] :: [] | tuple(),
- dir= 0 :: 0 | 1,
- top= [] :: [] | integer(),
- bot= [] :: [] | integer()}).
- #iter { id= [] :: [] | integer(),
- prev= [] :: [] | integer(),
- next= [] :: [] | integer()).
- </code></figure>
- </section>
- <section>
- <h3>EXAMPLE</h3>
- <figure><code>
- create_destroy() ->
- Cur = new(),
- [A,B,C,D] = [ kvs:next_id(person,1)
- || _ <- lists:seq(1,4) ],
- S = kvs_stream:save(
- kvs_stream:add(#person{id=A},
- kvs_stream:down(
- kvs_stream:add(#person{id=B},
- kvs_stream:up(
- kvs_stream:add(#person{id=C},
- kvs_stream:down(
- kvs_stream:add(#person{id=D},
- kvs_stream:up(
- kvs_stream:new()))))))))),
- Y = kvs_stream:remove(B,
- kvs_stream:remove(D,
- kvs_stream:remove(A,
- kvs_stream:remove(C,S)))),
- [] = kvs_stream:take(-1,
- kvs_stream:down(
- kvs_stream:top(Y))).
- </code></figure>
- </section>
- <section>
- <h3>API</h3>
- <h4>new() -> #cur{}.</h4>
- <p>Creates a KVS cursor.</p>
- <h4>save(#cur{}) -> #cur{}.</h4>
- <p>Saves cursor to database.<?p>
- <h4>load() -> #ok{data::#cur{}} | #error{}.</h4>
- <p>Gets a curson from database.</p>
- <h4>next(#cur{}) -> #cur{}.</h4>
- <p>Moves cursor to next. Consume data top down.</p>
- <h4>prev(#cur{}) -> #cur{}.</h4>
- <p>Moves cursor to prev. Consume data bottom up.</p>
- <h4>seek(Id,#cur{}) -> #cur{} | #error{}.</h4>
- <p>Moves cursor to Id record. If cursor has no cached value then function returns error.</p>
- <h4>top(#cur{}) -> #cur{}.</h4>
- <p>Moves cursor to top of the list.</p>
- <h4>bot(#cur{}) -> #cur{}.</h4>
- <p>Moves cursor to bottom of the list.</p>
- <h4>add(Message,#cur{}) -> #cur{}.</h4>
- <p>Adds message to datatabase and update cursor to new data.
- Message is linked on next prev fields with existed data under cursor.</p>
- <h4>remove(Id,#cur{}) -> #cur{} | #error{}.</h4>
- <p>Removes record by id from database and unlink it from list.
- If cursor has no cached value then function returns error.</p>
- <h4>take(N,#cur{}) -> list().</h4>
- <p>Consumes records from stream using its current value and direction. Returns consumed data.</p>
- </section>
- <section>
- <h3>CONFIG</h3>
- <p>In sys.config you should specify kvs backend and list of modules containing <b>metainfo/0</b> exported function.</p>
- <figure><code>
- [{kvs, [{dba, store_mnesia},
- {schema, [kvs]} ]}].
- </code></figure>
- </section>
- <section>
- <p>This module may refer to:
- <a href="http://erlang.org/doc/man/mnesia.html">mnesia</a></b>,
- <a href="kvs.htm"><b>kvs</b></a>.
- </p>
- </section>
- </main>
- <footer>
- 2005—2017 © Synrc Research Center
- </footer>
- </body>
- </html>
|