• 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 
16 #ifndef NAPI_RDB_CONTEXT_H
17 #define NAPI_RDB_CONTEXT_H
18 
19 #include "napi_async_call.h"
20 #include "napi_rdb_js_utils.h"
21 #include "napi_rdb_predicates.h"
22 #include "rdb_store.h"
23 #include "transaction.h"
24 #include "values_buckets.h"
25 
26 namespace OHOS {
27 namespace RelationalStoreJsKit {
28 class ResultSetProxy;
29 using namespace OHOS::NativeRdb;
30 struct RdbStoreContextBase : public ContextBase {
31     std::shared_ptr<NativeRdb::RdbStore> StealRdbStore();
32     std::shared_ptr<NativeRdb::RdbStore> rdbStore = nullptr;
33 };
34 
35 struct RdbStoreContext : public RdbStoreContextBase {
36     std::string device;
37     std::string tableName;
38     std::vector<std::string> tablesNames;
39     std::string whereClause;
40     std::string sql;
41     RdbPredicatesProxy *predicatesProxy;
42     std::vector<std::string> columns;
43     ValuesBucket valuesBucket;
44     std::vector<ValuesBucket> valuesBuckets;
45     ValuesBuckets sharedValuesBuckets;
46     std::map<std::string, ValueObject> numberMaps;
47     std::vector<ValueObject> bindArgs;
48     int64_t int64Output;
49     int intOutput;
50     ValueObject sqlExeOutput;
51     std::vector<uint8_t> newKey;
52     std::shared_ptr<ResultSet> resultSet;
53     std::string aliasName;
54     std::string pathName;
55     std::string srcName;
56     std::string columnName;
57     int32_t enumArg;
58     int32_t distributedType;
59     int32_t syncMode;
60     uint64_t cursor = UINT64_MAX;
61     int64_t txId = 0;
62     DistributedRdb::DistributedConfig distributedConfig;
63     napi_ref asyncHolder = nullptr;
64     NativeRdb::ConflictResolution conflictResolution;
65     DistributedRdb::SyncResult syncResult;
66     std::shared_ptr<RdbPredicates> rdbPredicates = nullptr;
67     std::vector<NativeRdb::RdbStore::PRIKey> keys;
68     std::map<RdbStore::PRIKey, RdbStore::Date> modifyTime;
69     bool isQuerySql = false;
70     uint32_t expiredTime = 0;
71     NativeRdb::RdbStoreConfig::CryptoParam cryptoParam;
72 
RdbStoreContextRdbStoreContext73     RdbStoreContext()
74         : predicatesProxy(nullptr), int64Output(0), intOutput(0), enumArg(-1),
75           distributedType(DistributedRdb::DistributedTableType::DISTRIBUTED_DEVICE),
76           syncMode(DistributedRdb::SyncMode::PUSH), conflictResolution(ConflictResolution::ON_CONFLICT_NONE)
77     {
78     }
~RdbStoreContextRdbStoreContext79     virtual ~RdbStoreContext()
80     {
81     }
82 };
83 
84 struct CreateTransactionContext : public RdbStoreContextBase {
85     AppDataMgrJsKit::JSUtils::TransactionOptions transactionOptions;
86     std::shared_ptr<Transaction> transaction;
87 };
88 
89 int ParseTransactionOptions(
90     const napi_env &env, size_t argc, napi_value *argv, std::shared_ptr<CreateTransactionContext> context);
91 int ParseTableName(const napi_env env, const napi_value arg, std::shared_ptr<RdbStoreContext> context);
92 
93 int ParseCursor(const napi_env env, const napi_value arg, std::shared_ptr<RdbStoreContext> context);
94 
95 int ParseCryptoParam(const napi_env env, const napi_value arg, std::shared_ptr<RdbStoreContext> context);
96 
97 int ParseColumnName(const napi_env env, const napi_value arg, std::shared_ptr<RdbStoreContext> context);
98 
99 int ParsePrimaryKey(const napi_env env, const napi_value arg, std::shared_ptr<RdbStoreContext> context);
100 
101 int ParseDevice(const napi_env env, const napi_value arg, std::shared_ptr<RdbStoreContext> context);
102 
103 int ParseTablesName(const napi_env env, const napi_value arg, std::shared_ptr<RdbStoreContext> context);
104 
105 int ParseSyncModeArg(const napi_env env, const napi_value arg, std::shared_ptr<RdbStoreContext> context);
106 
107 int ParseDistributedTypeArg(
108     const napi_env &env, size_t argc, napi_value *argv, std::shared_ptr<RdbStoreContext> context);
109 
110 int ParseDistributedConfigArg(
111     const napi_env &env, size_t argc, napi_value *argv, std::shared_ptr<RdbStoreContext> context);
112 
113 int ParseCloudSyncModeArg(const napi_env env, const napi_value arg, std::shared_ptr<RdbStoreContext> context);
114 
115 int ParseCallback(const napi_env env, const napi_value arg, std::shared_ptr<RdbStoreContext> context);
116 
117 int ParseCloudSyncCallback(const napi_env env, const napi_value arg, std::shared_ptr<RdbStoreContext> context);
118 
119 int ParsePredicates(const napi_env env, const napi_value arg, std::shared_ptr<RdbStoreContext> context);
120 
121 int ParseSrcType(const napi_env env, const napi_value arg, std::shared_ptr<RdbStoreContext> context);
122 
123 int ParseSrcName(const napi_env env, const napi_value arg, std::shared_ptr<RdbStoreContext> context);
124 
125 int ParseColumns(const napi_env env, const napi_value arg, std::shared_ptr<RdbStoreContext> context);
126 
127 int ParseBindArgs(const napi_env env, const napi_value arg, std::shared_ptr<RdbStoreContext> context);
128 
129 int ParseSql(const napi_env env, const napi_value arg, std::shared_ptr<RdbStoreContext> context);
130 
131 int ParseTxId(const napi_env env, const napi_value arg, std::shared_ptr<RdbStoreContext> context);
132 
133 int ParseSendableValuesBucket(const napi_env env, const napi_value map, std::shared_ptr<RdbStoreContext> context);
134 
135 int ParseValuesBucket(const napi_env env, const napi_value arg, std::shared_ptr<RdbStoreContext> context);
136 
137 int ParseValuesBuckets(const napi_env env, const napi_value arg, std::shared_ptr<RdbStoreContext> context);
138 
139 int ParseConflictResolution(const napi_env env, const napi_value arg, std::shared_ptr<RdbStoreContext> context);
140 } // namespace RelationalStoreJsKit
141 } // namespace OHOS
142 #endif // NAPI_RDB_CONTEXT_H