anchor.diff:    handle_transaction_attempt(CommitResult).
   
   attempt_transaction(DbHandle, DoStuff) ->
  -  {0, Tx} = fdb_nif:fdb_database_create_transaction(DbHandle),
  -  Result = DoStuff({tx, Tx}),
  -  ApplySelf = fun() -> attempt_transaction(DbHandle, DoStuff) end,
  -  CommitF = fdb_nif:fdb_transaction_commit(Tx), 
  -  {future(CommitF), Tx, Result, ApplySelf}.
  +  case fdb_nif:fdb_database_create_transaction(DbHandle) of
  +    {0, Tx} ->
  +      Result = DoStuff({tx, Tx}),
  +      ApplySelf = fun() -> attempt_transaction(DbHandle, DoStuff) end,
  +      CommitF = fdb_nif:fdb_transaction_commit(Tx), 
  +      {future(CommitF), Tx, Result, ApplySelf};
  +    Error -> Error
  +  end.
   
   handle_transaction_attempt({ok, _Tx, Result, _ApplySelf}) -> Result;
   handle_transaction_attempt({{error, Err}, Tx, _Result, ApplySelf}) ->
     OnErrorF = fdb_nif:fdb_transaction_on_error(Tx, Err),
     RetryAllowed = future(OnErrorF),
  -  maybe_reattempt_transaction(RetryAllowed, ApplySelf).
  +  maybe_reattempt_transaction(RetryAllowed, ApplySelf);
  +handle_transaction_attempt(nif_not_loaded) -> {error, nif_not_loaded}.
   
   maybe_reattempt_transaction(ok, ApplySelf) ->  ApplySelf();
   maybe_reattempt_transaction(Error, _ApplySelf) -> Error.
  
positive.code:     Select#select.is_reverse),
    {ok, EncodedData} = future_get(F, keyvalue_array),
    Data = lists:map(fun({X, Y})-> {tuple:unpack(X), binary_to_term(Y)} end, EncodedData),
    Iterator#iterator{ data = Data, iteration = Iteration + 1, out_more = Data /= []}.
  
  iterate_all(Iterator) ->
    iterate_all(next(Iterator), []).
  iterate_all(done, Result) -> Result;
  iterate_all(#iterator{data = Data, select = Select}, []) 
    when Select#select.limit == 0 andalso Select#select.target_bytes == 0
    -> Data;
  iterate_all(Iterator, Result) ->
    NewResult = Result++Iterator#iterator.data,
    Next = next(Iterator),
    iterate_all(Next, NewResult). 
  
  fst_gt(nil, nil) -> {<<0>>, true, 0};
  fst_gt(nil, Value) -> { tuple:pack(Value), true, 0  };
  
negative.code:   transact(DB, fun(Tx) -> get(Tx, Select) end);
  get(Tx={tx, _}, Select = #select{}) ->
    Iterator = bind(Tx, Select),
    Next = next(Iterator),
    Next#iterator.data;
  get(FdbHandle, Key) -> 
    get(FdbHandle, Key, not_found).
  
  %% @doc Gets a range of key_values where `begin <= X < end`
  -spec get_range(fdb_handle(), fdb_key(),fdb_key()) -> ([term()]|{error,nif_not_loaded}).
  %% @end
  get_range(Handle, Begin, End) ->
    get(Handle, #select{gte = Begin, lt = End}).
  