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 CLOUD_STORE_TYPE_H 17 #define CLOUD_STORE_TYPE_H 18 19 #include <functional> 20 #include <map> 21 #include <variant> 22 #include <string> 23 #include <stdint.h> 24 25 #include "store_types.h" 26 27 namespace DistributedDB { 28 enum TableSyncType { 29 DEVICE_COOPERATION = 0, 30 CLOUD_COOPERATION = 1, 31 }; 32 33 enum ClearMode { 34 DEFAULT = 0, // use for device to device sync 35 FLAG_AND_DATA = 1, // use for device to cloud sync 36 FLAG_ONLY = 2, 37 BUTT = 3, 38 }; 39 40 enum class AssetOpType { 41 NO_CHANGE = 0, 42 INSERT, 43 DELETE, 44 UPDATE 45 }; 46 47 enum AssetStatus : uint32_t { 48 NORMAL = 0, 49 DOWNLOADING, 50 ABNORMAL, 51 INSERT, // INSERT/DELETE/UPDATE are for client use 52 DELETE, 53 UPDATE 54 }; 55 56 struct Asset { 57 uint32_t version = 0; 58 std::string name; 59 std::string assetId; 60 std::string subpath; 61 std::string uri; 62 std::string modifyTime; 63 std::string createTime; 64 std::string size; 65 std::string hash; 66 uint32_t flag = static_cast<uint32_t>(AssetOpType::NO_CHANGE); 67 uint32_t status = static_cast<uint32_t>(AssetStatus::NORMAL); 68 int64_t timestamp = 0; 69 }; 70 using Nil = std::monostate; 71 using Assets = std::vector<Asset>; 72 using Bytes = std::vector<uint8_t>; 73 using Type = std::variant<Nil, int64_t, double, std::string, bool, Bytes, Asset, Assets>; 74 using VBucket = std::map<std::string, Type>; 75 76 struct Field { 77 std::string colName; 78 int32_t type; // get value from TYPE_INDEX; 79 bool primary = false; 80 bool nullable = true; 81 }; 82 83 struct TableSchema { 84 std::string name; 85 std::vector<Field> fields; 86 }; 87 88 struct DataBaseSchema { 89 std::vector<TableSchema> tables; 90 }; 91 92 } // namespace DistributedDB 93 #endif // CLOUD_STORE_TYPE_H