• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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 #ifndef OHOS_MEDIA_CLOUD_SYNC_DATABASE_H
16 #define OHOS_MEDIA_CLOUD_SYNC_DATABASE_H
17 
18 #include <functional>
19 #include <map>
20 #include <string>
21 #include <vector>
22 #include <mutex>
23 #include <shared_mutex>
24 #include <list>
25 
26 #include "mdk_record.h"
27 #include "mdk_result.h"
28 
29 #define EXPORT __attribute__ ((visibility ("default")))
30 
31 namespace OHOS::Media::CloudSync {
32 struct MDKSchemaField {
33     std::string name;             // 名称
34     MDKRecordFieldType type;      // 数据类型
35     bool primary;                 // 是否为云端主键
36     bool nullable;                // 是否可为空
37     bool sortable;                // 是否支持排序
38     bool searchable;              // 是否支持搜索
39     bool queryable;               // 是否支持查询
40     MDKRecordFieldType listType;  // 当type为list时,listType表示list的类型
41     std::string refRecordType;    // 当type或listType为Reference类型时,该字段表示被引用的RecordType
42 };
43 
44 struct MDKSchemaRelation {
45     std::string relationName;
46     std::string recordType;
47     std::map<std::string, std::string> refFields;  // 可选,源表字段和目标表字段映射关系
48 };
49 
50 struct MDKSchemaNode {
51     std::string recordType;  // 云端表名 kind
52     std::string tableName;   // 本地表名
53     std::map<std::string, MDKSchemaField> fields;
54     std::vector<std::string> dupCheckFields;   // 端侧去重主键
55     std::string sharedTableName;               // 本地分享表名(可选)
56     std::vector<MDKSchemaRelation> relations;  // 关联关系
57 };
58 
59 struct MDKOrderTable {
60     std::string recordType;  // 云端表名 kind
61     std::string tableName;   // 本地表名
62 };
63 
64 struct MDKSchema {
65     int64_t version;  // 应用使用的schema version
66     std::map<std::string, MDKSchemaNode> recordTypes;
67     std::string schemaData;                  // schema的原始json字符串
68     std::vector<MDKOrderTable> orderTables;  // 与schema中顺序一致
69 };
70 }  // namespace OHOS::Media::CloudSync
71 #endif