• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "query.h"
26 #include "store_types.h"
27 
28 namespace DistributedDB {
29 enum TableSyncType {
30     DEVICE_COOPERATION = 0,
31     CLOUD_COOPERATION = 1,
32 };
33 
34 enum ClearMode {
35     DEFAULT = 0,        // use for device to device sync
36     FLAG_AND_DATA = 1,  // use for device to cloud sync
37     FLAG_ONLY = 2,
38     CLEAR_SHARED_TABLE = 3,
39     BUTT = 4,
40 };
41 
42 enum class AssetOpType {
43     NO_CHANGE = 0,
44     INSERT,
45     DELETE,
46     UPDATE
47 };
48 
49 enum AssetStatus : uint32_t {
50     NORMAL = 0,
51     DOWNLOADING,
52     ABNORMAL,
53     INSERT, // INSERT/DELETE/UPDATE are for client use
54     DELETE,
55     UPDATE,
56     // high 16 bit USE WITH BIT MASK
57     DOWNLOAD_WITH_NULL = 0x40000000,
58     UPLOADING = 0x80000000,
59 };
60 
61 struct Asset {
62     uint32_t version = 0;
63     std::string name;
64     std::string assetId;
65     std::string subpath;
66     std::string uri;
67     std::string modifyTime;
68     std::string createTime;
69     std::string size;
70     std::string hash;
71     uint32_t flag = static_cast<uint32_t>(AssetOpType::NO_CHANGE);
72     uint32_t status = static_cast<uint32_t>(AssetStatus::NORMAL);
73     int64_t timestamp = 0;
74     bool operator==(const Asset& asset) const
75     {
76         if (this == &asset) {
77             return true;
78         }
79         // force check all field
80         return (version == asset.version) && (name == asset.name) && (assetId == asset.assetId) &&
81             (subpath == asset.subpath) && (uri == asset.uri) && (modifyTime == asset.modifyTime) &&
82             (createTime == asset.createTime) && (size == asset.size) && (hash == asset.hash) && (flag == asset.flag) &&
83             (status == asset.status) && (timestamp == asset.timestamp);
84     }
85 };
86 using Nil = std::monostate;
87 using Assets = std::vector<Asset>;
88 using Bytes = std::vector<uint8_t>;
89 using Entries = std::map<std::string, std::string>;
90 using Type = std::variant<Nil, int64_t, double, std::string, bool, Bytes, Asset, Assets, Entries>;
91 using VBucket = std::map<std::string, Type>;
92 
93 struct Field {
94     std::string colName;
95     int32_t type; // get value from TYPE_INDEX;
96     bool primary = false;
97     bool nullable = true;
98     bool operator==(const Field &comparedField) const
99     {
100         return (colName == comparedField.colName) && (type == comparedField.type) &&
101             (primary == comparedField.primary) && (nullable == comparedField.nullable);
102     }
103 };
104 
105 struct TableSchema {
106     std::string name;
107     std::string sharedTableName; // if table is shared table, its sharedtablename is ""
108     std::vector<Field> fields;
109 };
110 
111 struct DataBaseSchema {
112     std::vector<TableSchema> tables;
113 };
114 
115 enum class CloudQueryType : int64_t {
116     FULL_TABLE = 0, // query full table
117     QUERY_FIELD = 1 // query with some fields
118 };
119 
120 struct CloudSyncOption {
121     std::vector<std::string> devices;
122     SyncMode mode = SyncMode::SYNC_MODE_CLOUD_MERGE;
123     Query query;
124     int64_t waitTime = 0;
125     bool priorityTask = false;
126 };
127 
128 enum class QueryNodeType : uint32_t {
129     ILLEGAL = 0,
130     IN = 1,
131     OR = 0x101,
132     AND,
133     EQUAL_TO = 0x201,
134     BEGIN_GROUP = 0x301,
135     END_GROUP
136 };
137 
138 struct QueryNode {
139     QueryNodeType type = QueryNodeType::ILLEGAL;
140     std::string fieldName;
141     std::vector<Type> fieldValue;
142 };
143 
144 struct SqlCondition {
145     std::string sql;  // The sql statement;
146     std::vector<Type> bindArgs;  // The bind args.
147     bool readOnly = false;
148 };
149 
150 enum class RecordStatus {
151     WAIT_COMPENSATED_SYNC
152 };
153 } // namespace DistributedDB
154 #endif // CLOUD_STORE_TYPE_H