|
@@ -60,47 +60,35 @@
|
|
|
<h3>EXAMPLE</h3>
|
|
|
|
|
|
<figure><code>
|
|
|
- create_destroy() ->
|
|
|
+-module(kvs_stream).
|
|
|
+-compile(export_all).
|
|
|
+
|
|
|
+check() ->
|
|
|
Cur = new(),
|
|
|
+ take(-1,down(top(Cur))),
|
|
|
[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))).
|
|
|
+ R = save(add(top,#person{id=A},
|
|
|
+ add(bot,#person{id=B},
|
|
|
+ add(top,#person{id=C},
|
|
|
+ add(bot,#person{id=D}, Cur ))))),
|
|
|
+ X = take(-1,down(top(R))),
|
|
|
+ Y = take(-1,up(bot(R))),
|
|
|
+ X = lists:reverse(Y),
|
|
|
+ L = length(X).
|
|
|
|
|
|
> kvs_stream:check().
|
|
|
- ok
|
|
|
+ 4
|
|
|
|
|
|
> kvs:all(cur).
|
|
|
- [{cur,8,[],0,[],[]},
|
|
|
- {cur,4,[],0,[],[]},
|
|
|
- {cur,9,{person,21,23,[],[],[],[],[],[]},0,21,22},
|
|
|
- {cur,6,{person,13,15,[],[],[],[],[],[]},0,13,14},
|
|
|
- {cur,5,{person,9,11,[],[],[],[],[],[]},0,9,10}]
|
|
|
-
|
|
|
-> kvs_stream:take(-1,
|
|
|
- kvs_stream:down(
|
|
|
- kvs_stream:top(
|
|
|
- kvs_stream:seek(24,
|
|
|
- kvs:get(cur,9))))).
|
|
|
-[{person,22,[],24,[],[],[],[],[]},
|
|
|
- {person,24,22,23,[],[],[],[],[]},
|
|
|
- {person,23,24,21,[],[],[],[],[]},
|
|
|
- {person,21,23,[],[],[],[],[],[]}]
|
|
|
+ [{cur,1,{person,1,3,[],[],[],[],[],[]},0,1,2}]
|
|
|
+
|
|
|
+ > kvs_stream:take(-1,
|
|
|
+ kvs_stream:top(kvs:get(cur,1))).
|
|
|
+[{person,2,[],4,[],[],[],[],[]},
|
|
|
+ {person,4,2,3,[],[],[],[],[]},
|
|
|
+ {person,3,4,1,[],[],[],[],[]},
|
|
|
+ {person,1,3,[],[],[],[],[],[]}]
|
|
|
|
|
|
</code></figure>
|
|
|
</section>
|
|
@@ -114,17 +102,17 @@
|
|
|
|
|
|
<h4>save(#cur{}) -> #cur{}.</h4>
|
|
|
|
|
|
-<p>Saves cursor to database.<?p>
|
|
|
+<p>Saves the cursor to database.<?p>
|
|
|
|
|
|
<h4>load() -> #ok{data::#cur{}} | #error{}.</h4>
|
|
|
|
|
|
-<p>Gets a curson from database.</p>
|
|
|
+<p>Gets a cursor from database.</p>
|
|
|
|
|
|
-<h4>next(#cur{}) -> #cur{}.</h4>
|
|
|
+<h4>next(#cur{}) -> #cur{} | #error{}.</h4>
|
|
|
|
|
|
<p>Moves cursor to next. Consume data top down.</p>
|
|
|
|
|
|
-<h4>prev(#cur{}) -> #cur{}.</h4>
|
|
|
+<h4>prev(#cur{}) -> #cur{} | #error{}.</h4>
|
|
|
|
|
|
<p>Moves cursor to prev. Consume data bottom up.</p>
|
|
|
|
|
@@ -133,11 +121,11 @@
|
|
|
<p>Moves cursor to record by its id.
|
|
|
If cursor has no cached value then function returns error.</p>
|
|
|
|
|
|
-<h4>top(#cur{}) -> #cur{}.</h4>
|
|
|
+<h4>top(#cur{}) -> #cur{} | #error{}.</h4>
|
|
|
|
|
|
<p>Moves cursor to top of the list.</p>
|
|
|
|
|
|
-<h4>bot(#cur{}) -> #cur{}.</h4>
|
|
|
+<h4>bot(#cur{}) -> #cur{} | #error{}.</h4>
|
|
|
|
|
|
<p>Moves cursor to bottom of the list.</p>
|
|
|
|