1 /* 2 * Copyright (c) 2021 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_LOCAL_DB_HANDLE_H 17 #define SQLITE_LOCAL_DB_HANDLE_H 18 19 #include "sqlite_import.h" 20 #include "macro_utils.h" 21 #include "db_types.h" 22 #include "sqlite_storage_executor.h" 23 24 namespace DistributedDB { 25 class SQLiteLocalStorageExecutor : public SQLiteStorageExecutor { 26 public: 27 SQLiteLocalStorageExecutor(sqlite3 *dbHandle, bool writable, bool isMemDb); 28 ~SQLiteLocalStorageExecutor() override; 29 30 // Delete the copy and assign constructors 31 DISABLE_COPY_ASSIGN_MOVE(SQLiteLocalStorageExecutor); 32 33 int Get(const Key &key, Value &value) const; 34 35 // Put the value to the sqlite database 36 int Put(const Key &key, const Value &value); 37 38 // Delete the value from the sqlite database 39 int Delete(const Key &key); 40 41 // Clear all the data from the sqlite database 42 int Clear(); 43 44 // Get all the data which have the prefix key from the sqlite database 45 int GetEntries(const Key &keyPrefix, std::vector<Entry> &entries) const; 46 47 // Put the batch data to the sqlite database 48 int PutBatch(const std::vector<Entry> &entries); 49 50 // Delete the batch data from the sqlite database according to the key from the set 51 int DeleteBatch(const std::vector<Key> &keys); 52 53 // Next step interface 54 // Start the transaction 55 int StartTransaction(); 56 57 // Commit the transaction 58 int Commit(); 59 60 // Roll back the transaction 61 int RollBack(); 62 }; 63 } // namespace DistributedDB 64 #endif // SQLITE_LOCAL_DB_HANDLE_H 65