Couchbase Transactions C++ Client  1.0.0
Transactions client for couchbase
mutate_in_spec.hxx
Go to the documentation of this file.
1 /*
2  * Copyright 2021 Couchbase, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <string>
20 
21 #include <couchbase/internal/nlohmann/json.hpp>
22 
29 namespace couchbase
30 {
31 class collection;
32 
33 enum class mutate_in_spec_type { MUTATE_IN_UPSERT, MUTATE_IN_INSERT, MUTATE_IN_FULLDOC_INSERT, MUTATE_IN_FULLDOC_UPSERT, REMOVE };
34 
42 namespace mutate_in_macro
43 {
45  static const std::string CAS = "${Mutation.CAS}";
47  static const std::string SEQ_NO = "${Mutation.seqno}";
49  static const std::string VALUE_CRC_32C = "${Mutation.value_crc32c}";
50 }; // namespace mutate_in_macro
51 
64 {
65  friend collection;
66 
67  public:
77  template<typename Content>
78  static mutate_in_spec upsert(const std::string& path, const Content& value)
79  {
80  return mutate_in_spec(mutate_in_spec_type::MUTATE_IN_UPSERT, path, value);
81  }
82 
92  template<typename Content>
93  static mutate_in_spec insert(const std::string& path, const Content& value)
94  {
95  return mutate_in_spec(mutate_in_spec_type::MUTATE_IN_INSERT, path, value);
96  }
97 
106  template<typename Content>
107  static mutate_in_spec fulldoc_insert(const Content& value)
108  {
109  return mutate_in_spec(mutate_in_spec_type::MUTATE_IN_FULLDOC_INSERT, value);
110  }
111 
120  template<typename Content>
121  static mutate_in_spec fulldoc_upsert(const Content& value)
122  {
123  return mutate_in_spec(mutate_in_spec_type::MUTATE_IN_FULLDOC_UPSERT, value);
124  }
125 
132  static mutate_in_spec remove(const std::string& path)
133  {
134  return mutate_in_spec(mutate_in_spec_type::REMOVE, path, std::string(""));
135  }
136 
143 
150 
157 
158  private:
159  mutate_in_spec_type type_;
160  std::string path_;
161  std::string value_;
162  uint32_t flags_;
163 
164  mutate_in_spec(mutate_in_spec_type type, std::string path, const nlohmann::json& value)
165  : type_(type)
166  , path_(std::move(path))
167  , value_(value.dump())
168  , flags_(0)
169  {
170  }
171  mutate_in_spec(mutate_in_spec_type type, const nlohmann::json& value)
172  : type_(type)
173  , path_("")
174  , value_(value.dump())
175  , flags_(0)
176  {
177  }
178 };
179 
180 } // namespace couchbase
Definition: bucket.hxx:33
mutate_in_spec & xattr()
Specify the mutation is on xattrs, rather than the document body.
STL namespace.
static mutate_in_spec insert(const std::string &path, const Content &value)
Insert content at a path within a document.
Definition: mutate_in_spec.hxx:93
static mutate_in_spec upsert(const std::string &path, const Content &value)
Upsert content at a path within a document.
Definition: mutate_in_spec.hxx:78
mutate_in_spec & create_path()
Specify the mutation creates the entire path.
mutate_in_spec & expand_macro()
Specify the value in this mutation spec contains a mutate_in_macro.
static mutate_in_spec fulldoc_insert(const Content &value)
Inserts the content as the entire body of the document.
Definition: mutate_in_spec.hxx:107
Specify specific elements in a document to mutate.
Definition: mutate_in_spec.hxx:63
Exposes collection-level kv operations.
Definition: collection.hxx:46
static mutate_in_spec fulldoc_upsert(const Content &value)
Upsert the content as the entire body of the document.
Definition: mutate_in_spec.hxx:121