anchor.diff:              ensure_error(Error)
       end.
   
  +%% @doc Update record `Rec'. Uses the prepared query with name
  +%% `RecName_update'. Assumes an `id' field and corresponding column
  +%% which is used to find the row to update. The fields from `Rec'
  +%% passed as parameters to the query are determined by
  +%% `RecName:'#update_fields/0'.
   -spec update(db_rec()) -> ok | {error, _}.
   update(Rec) ->
       RecName = rec_name(Rec),
  
positive.code:     case sqerl:select(Query, Vals) of
          {ok, none} ->
              [];
          %% match on single row result
          {ok, Rows} ->
              rows_to_recs(Rows, RecName);
          Error ->
              ensure_error(Error)
      end.
  
  -spec fetch(atom(), atom(), any()) -> [db_rec()] | {error, _}.
  fetch(RecName, By, Val) ->
      Query = join_atoms([RecName, '_', fetch_by, '_', By]),
      qfetch(RecName, Query, [Val]).
  
  -spec fetch_all(atom()) -> [db_rec()] | {error, _}.
  fetch_all(RecName) ->
      Query = join_atoms([RecName, '_', fetch_all]),
      qfetch(RecName, Query, []).
  
  -spec fetch_page(atom(), string(), integer()) -> [db_rec()] | {error, _}.
  fetch_page(RecName, StartName, Limit) ->
      Query = join_atoms([RecName, '_', fetch_page]),
      qfetch(RecName, Query, [StartName, Limit]).
  
  first_page() ->
      %% ascii value that sorts less or equal to any valid name.
      "\001".
  
  -spec insert(db_rec()) -> [db_rec()] | {error, _}.
  insert(Rec) ->
      RecName = rec_name(Rec),
  
negative.code:     B;
  as_bin(S) ->
      erlang:iolist_to_binary(S).
  
  rec_name(Rec) ->
      erlang:element(1, Rec).
  