anchor.diff:  -export([code_change/3]).
   -export([handle_cast/2]).
   
  +-record(state, {dbid, hackney_ref, hackney_acc, first_seq, buffer=[]}).
  +
  +
   start(Name, Store) ->
     gen_server:call(?MODULE, {start, Name, Store}).
   
  
positive.code:            end,
   lists:foldr(Folder, Acc, Results).
  
  req(Method,Url) ->
    req(Method, Url, []).
  
  
negative.code:   {error, not_implemented}.
  
  infos(DbRef) ->
    gen_server:call(?MODULE, {infos, DbRef}).
  
  post(DbRef, Doc, Options) ->
    gen_server:call(?MODULE, {post, DbRef, Doc, Options}).
  
  put(DbRef, DocId, Doc, Options) ->
    gen_server:call(?MODULE, {put, DbRef, DocId, Doc, Options}).
  
  put_rev(_Db, _DocId, _Body, _History, _Options) ->
    {error, not_implemented}.
  
  get(DbRef, DocId, Options) ->
    gen_server:call(?MODULE, {get, DbRef, DocId, Options}).
  
  delete(DbRef, DocId, RevId, Options) ->
    gen_server:call(?MODULE, {delete, DbRef, DocId, RevId, Options}).
  
  fold_by_id(_Db, _Fun, _Acc, _Opts) ->
    {error, not_implemented}.
  
  changes_since(BarrelId, Since, Fun, Acc) ->
    gen_server:call(?MODULE, {changes_since, BarrelId, Since, Fun, Acc}).
  
  revsdiff(_Db, _DocId, _RevIds) ->
    {error, not_implemented}.
  
  %% ----------
  
  start_link() ->
    case gen_server:start_link({local, ?MODULE}, ?MODULE, [], []) of
      {ok, Pid} -> {ok, Pid};
      {error, {already_started, Pid}} -> {ok, Pid}
    end.
  
  stop() ->
    gen_server:call(?MODULE, stop).
  
  init(_) ->
    {ok, #state{}}.
  
  handle_call({start, DbRef, _}, _From, State) ->
    {_, DbId} = DbRef,
    Since = 0, % TODO: pass it in parameter
    gen_server:cast(?MODULE, {longpoll, DbRef, Since}),
    {reply, ok, State#state{dbid=DbId}};
  
  handle_call({infos, DbRef}, _From, State) ->
    {_, BarrelId} = DbRef,
    {200, R} = req(get, BarrelId),
    Info = jsx:decode(R, [return_maps]),
    {reply, {ok, Info}, State};
  
  handle_call({post, DbRef, Doc, _Options}, _From, State) ->
    {_, BarrelId} = DbRef,
    post_put(post, BarrelId, Doc, State);
  
  handle_call({put, DbRef, DocId, Doc, _Options}, _From, State) ->
    Sep = <<"/">>,
    {_, BarrelId} = DbRef,
    Url = <<BarrelId/binary, Sep/binary, DocId/binary>>,
    post_put(put, Url, Doc, State);
  
  handle_call({get, DbRef, DocId, _Options}, _From, State) ->
    {_, BarrelId} = DbRef,
    Sep = <<"/">>,
    Url = <<BarrelId/binary, Sep/binary, DocId/binary>>,
    {Code, Reply} = req(get, Url),
    get_resp(Code, Reply, State);
  
  handle_call({delete, DbRef, DocId, RevId, _Options}, _From, State) ->
    Sep = <<"/">>,
    Rev = <<"?rev=">>,
    {_, BarrelId} = DbRef,
  