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 OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CLOUD_SCHEMA_META_H 17 #define OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CLOUD_SCHEMA_META_H 18 #include "serializable/serializable.h" 19 namespace OHOS::DistributedData { 20 struct API_EXPORT Field final : public Serializable { 21 std::string colName; 22 std::string alias; 23 int32_t type = 0; 24 bool primary = false; 25 bool nullable = true; 26 bool Marshal(json &node) const override; 27 bool Unmarshal(const json &node) override; 28 }; 29 30 struct API_EXPORT Table final : public Serializable { 31 std::string name; 32 std::string alias; 33 std::vector<Field> fields; 34 bool Marshal(json &node) const override; 35 bool Unmarshal(const json &node) override; 36 }; 37 38 struct API_EXPORT Database final : public Serializable { 39 std::string name = ""; 40 std::string alias; 41 std::vector<Table> tables; 42 std::vector<std::string> GetTableNames() const; 43 bool Marshal(json &node) const override; 44 bool Unmarshal(const json &node) override; 45 }; 46 47 class API_EXPORT SchemaMeta final : public Serializable { 48 public: 49 using Database = Database; 50 using Table = Table; 51 using Field = Field; 52 static constexpr const char *DELETE_FIELD = "#_deleted"; 53 static constexpr const char *GID_FIELD = "#_gid"; 54 static constexpr const char *CREATE_FIELD = "#_createTime"; 55 static constexpr const char *MODIFY_FIELD = "#_modifyTime"; 56 static constexpr const char *CURSOR_FIELD = "#_cursor"; 57 static constexpr const char *ERROR_FIELD = "#_error"; 58 int32_t version = 0; 59 std::string bundleName; 60 std::vector<Database> databases; 61 62 bool Marshal(json &node) const override; 63 bool Unmarshal(const json &node) override; 64 bool IsValid() const; 65 Database GetDataBase(const std::string &storeId); 66 }; 67 } // namespace OHOS::DistributedData 68 #endif // OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CLOUD_SCHEMA_META_H 69