1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef COLLECTION_H 17 #define COLLECTION_H 18 19 #include <string> 20 21 #include "check_common.h" 22 #include "kv_store_executor.h" 23 24 namespace DocumentDB { 25 class Collection { 26 public: 27 Collection(const std::string &name, KvStoreExecutor *executor); 28 ~Collection(); 29 30 int InsertDocument(const std::string &id, const std::string &document, bool &isIdExist); 31 int GetDocumentById(Key &key, Value &document) const; 32 int GetMatchedDocument(const JsonObject &filterObj, Key &key, std::pair<std::string, std::string> &values, 33 int isIdExist) const; 34 int DeleteDocument(Key &key); 35 int IsCollectionExists(int &errCode); 36 int UpsertDocument(const std::string &id, const std::string &newDocument, bool &isIdExist); 37 int UpdateDocument(const std::string &id, const std::string &document); 38 39 private: 40 int InsertUntilSuccess(Key &key, const std::string &id, Value &valSet); 41 std::string name_; 42 KvStoreExecutor *executor_ = nullptr; 43 }; 44 } // namespace DocumentDB 45 #endif // COLLECTION_H