<commit_before>%% @author Couchbase <<EMAIL>>
%% @copyright 2011 Couchbase, Inc.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%%      http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.
%%

-module(capi_crud).

-include("couch_db.hrl").
-include("mc_entry.hrl").
-include("mc_constants.hrl").

-export([open_doc/3, update_doc/3]).

-spec open_doc(#db{}, binary(), list()) -> any().
open_doc(_Db, <<?LOCAL_DOC_PREFIX, _/binary>>, _Options) ->
    {not_found, missing};

open_doc(#db{name = Name, user_ctx = UserCtx}, DocId, Options) ->
    get(Name, DocId, UserCtx, Options).

update_doc(_Db, #doc{id = <<?LOCAL_DOC_PREFIX, _/binary>>}, _Options) ->
    Rev = {1, encode_revid(cas(), <<>>, 0)},
    {ok, Rev};

update_doc(#db{name = Name, user_ctx = UserCtx},
           #doc{id = DocId, revs = {SeqNo, [RevId|_]}, deleted = true},
           _Options) ->
    delete(Name, DocId, {SeqNo, RevId}, UserCtx);

update_doc(#db{name = Name, user_ctx = UserCtx},
           #doc{id = DocId, body = Body, atts = Atts, revs = {0, []}},
           _Options) ->
    add(Name, DocId, Body, Atts, UserCtx);

update_doc(#db{name = Name, user_ctx = UserCtx},
           #doc{id = DocId, revs = {SeqNo, [RevId | _]},
                body = Body, atts = Atts}, _Options) ->
    set(Name, DocId, {SeqNo, RevId}, Body, Atts, UserCtx).

-spec cas() -> <<_:64>>.
cas() -><commit_msg>Use the same revision format for _local/ docs as couchdb.<commit_after>%% @author Couchbase <<EMAIL>>
%% @copyright 2011 Couchbase, Inc.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%%      http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.
%%

-module(capi_crud).

-include("couch_db.hrl").
-include("mc_entry.hrl").
-include("mc_constants.hrl").

-export([open_doc/3, update_doc/3]).

-spec open_doc(#db{}, binary(), list()) -> any().
open_doc(_Db, <<?LOCAL_DOC_PREFIX, _/binary>>, _Options) ->
    {not_found, missing};

open_doc(#db{name = Name, user_ctx = UserCtx}, DocId, Options) ->
    get(Name, DocId, UserCtx, Options).

update_doc(_Db, #doc{id = <<?LOCAL_DOC_PREFIX, _/binary>>}, _Options) ->
    {ok, {0, <<"1">>}};

update_doc(#db{name = Name, user_ctx = UserCtx},
           #doc{id = DocId, revs = {SeqNo, [RevId|_]}, deleted = true},
           _Options) ->
    delete(Name, DocId, {SeqNo, RevId}, UserCtx);

update_doc(#db{name = Name, user_ctx = UserCtx},
           #doc{id = DocId, body = Body, atts = Atts, revs = {0, []}},
           _Options) ->
    add(Name, DocId, Body, Atts, UserCtx);

update_doc(#db{name = Name, user_ctx = UserCtx},
           #doc{id = DocId, revs = {SeqNo, [RevId | _]},
                body = Body, atts = Atts}, _Options) ->
    set(Name, DocId, {SeqNo, RevId}, Body, Atts, UserCtx).

-spec cas() -> <<_:64>>.
cas() ->
{'fraction_non_alphanumeric': 0.16932380428807037, 'fraction_numerical': 0.008246289169873557, 'mean_word_length': 3.6475095785440614, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7175091', 'n_tokens_mistral': 1256, 'n_tokens_neox': 1239, 'n_words': 374}