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 SQLITE_STORE_EXECUTOR_IMPL_H
17 #define SQLITE_STORE_EXECUTOR_IMPL_H
18 
19 #include "db_config.h"
20 #include "json_common.h"
21 #include "kv_store_executor.h"
22 #include "sqlite3.h"
23 
24 namespace DocumentDB {
25 class SqliteStoreExecutorImpl : public KvStoreExecutor {
26 public:
27     static int CreateDatabase(const std::string &path, const DBConfig &config, sqlite3 *&db);
28 
29     SqliteStoreExecutorImpl() = default;
30     explicit SqliteStoreExecutorImpl(sqlite3 *handle);
31     ~SqliteStoreExecutorImpl() override;
32 
33     int GetDBConfig(std::string &config);
34     int SetDBConfig(const std::string &config);
35 
36     int StartTransaction() override;
37     int Commit() override;
38     int Rollback() override;
39 
40     int PutData(const std::string &collName, Key &key, const Value &value, bool isNeedAddKeyType = true) override;
41     int InsertData(const std::string &collName, Key &key, const Value &value, bool isNeedAddKeyType = true) override;
42     int GetDataByKey(const std::string &collName, Key &key, Value &value) const override;
43     int GetDataById(const std::string &collName, Key &key, Value &value) const override;
44     int GetDataByFilter(const std::string &collName, Key &key, const JsonObject &filterObj,
45         std::pair<std::string, std::string> &values, int isIdExist) const override;
46     int DelData(const std::string &collName, Key &key) override;
47 
48     int CreateCollection(const std::string &name, const std::string &option, bool ignoreExists) override;
49     int DropCollection(const std::string &name, bool ignoreNonExists) override;
50     bool IsCollectionExists(const std::string &name, int &errCode) override;
51 
52     int SetCollectionOption(const std::string &name, const std::string &option) override;
53     int CleanCollectionOption(const std::string &name) override;
54 
55 private:
56     sqlite3 *dbHandle_ = nullptr;
57 };
58 } // namespace DocumentDB
59 #endif // SQLITE_STORE_EXECUTOR_IMPL_H