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 GRD_API_MANAGER_H 17 #define GRD_API_MANAGER_H 18 19 #include "grd_base/grd_type_export.h" 20 21 namespace DocumentDB { 22 typedef int32_t (*DBOpen)(const char *dbPath, const char *configStr, uint32_t flags, GRD_DB **db); 23 typedef int32_t (*DBClose)(GRD_DB *db, uint32_t flags); 24 typedef int32_t (*DBBackup)(GRD_DB *db, const char *backupDbFile, GRD_CipherInfoT *cipherInfo); 25 typedef int32_t (*DBRestore)(const char *dbFile, const char *backupDbFile, GRD_CipherInfoT *cipherInfo); 26 typedef int32_t (*DBFlush)(GRD_DB *db, uint32_t flags); 27 typedef int32_t (*IndexPreload)(GRD_DB *db, const char *collectionName); 28 typedef int32_t (*CreateCollection)(GRD_DB *db, const char *collectionName, const char *optionStr, uint32_t flags); 29 typedef int32_t (*DropCollection)(GRD_DB *db, const char *collectionName, uint32_t flags); 30 typedef int32_t (*InsertDoc)(GRD_DB *db, const char *collectionName, const char *document, uint32_t flags); 31 typedef int32_t (*FindDoc)(GRD_DB *db, const char *collectionName, Query query, 32 uint32_t flags, GRD_ResultSet **resultSet); 33 typedef int32_t (*UpdateDoc)(GRD_DB *db, const char *collectionName, const char *filter, 34 const char *update, uint32_t flags); 35 typedef int32_t (*UpsertDoc)(GRD_DB *db, const char *collectionName, const char *filter, 36 const char *document, uint32_t flags); 37 typedef int32_t (*DeleteDoc)(GRD_DB *db, const char *collectionName, const char *filter, uint32_t flags); 38 typedef int32_t (*ResultNext)(GRD_ResultSet *resultSet); 39 typedef int32_t (*ResultPrev)(GRD_ResultSet *resultSet); 40 typedef int32_t (*GetValue)(GRD_ResultSet *resultSet, char **value); 41 typedef int32_t (*Fetch)(GRD_ResultSet *resultSet, GRD_KVItemT *key, GRD_KVItemT *value); 42 typedef int32_t (*FreeValue)(char *value); 43 typedef int32_t (*FreeResultSet)(GRD_ResultSet *resultSet); 44 typedef int32_t (*KVPut)(GRD_DB *db, const char *collectionName, const GRD_KVItemT *key, const GRD_KVItemT *value); 45 typedef int32_t (*KVGet)(GRD_DB *db, const char *collectionName, const GRD_KVItemT *key, const GRD_KVItemT *value); 46 typedef int32_t (*KVDel)(GRD_DB *db, const char *collectionName, const GRD_KVItemT *key); 47 typedef int32_t (*KVScan)(GRD_DB *db, const char *collectionName, const GRD_KVItemT *key, GRD_KvScanModeE mode, 48 GRD_ResultSet **resultSet); 49 typedef int32_t (*KVFilter)(GRD_DB *db, const char *collectionName, const GRD_FilterOptionT *scanParams, 50 GRD_ResultSet **resultSet); 51 typedef int32_t (*KVGetSize)(GRD_ResultSet *resultSet, uint32_t *keyLen, uint32_t *valueLen); 52 typedef int32_t (*GetItem)(GRD_ResultSet *resultSet, void *key, void *value); 53 typedef int32_t (*KVFreeItem)(GRD_KVItemT *item); 54 typedef int32_t (*KVBatchPrepare)(uint16_t itemNum, GRD_KVBatchT **batch); 55 typedef int32_t (*KVBatchPushback)(const void *key, uint32_t keyLen, const void *data, uint32_t dataLen, 56 GRD_KVBatchT *batch); 57 typedef int32_t (*KVBatchPut)(GRD_DB *db, const char *collectionName, GRD_KVBatchT *batch); 58 typedef int32_t (*KVBatchDel)(GRD_DB *db, const char *collectionName, GRD_KVBatchT *batch); 59 typedef int32_t (*KVBatchDestroy)(GRD_KVBatchT *batch); 60 struct GRD_APIInfo { 61 DBOpen DBOpenApi = nullptr; 62 DBClose DBCloseApi = nullptr; 63 DBBackup DBBackupApi = nullptr; 64 DBRestore DBRestoreApi = nullptr; 65 DBFlush FlushApi = nullptr; 66 IndexPreload IndexPreloadApi = nullptr; 67 CreateCollection CreateCollectionApi = nullptr; 68 DropCollection DropCollectionApi = nullptr; 69 InsertDoc InsertDocApi = nullptr; 70 FindDoc FindDocApi = nullptr; 71 UpdateDoc UpdateDocApi = nullptr; 72 UpsertDoc UpsertDocApi = nullptr; 73 DeleteDoc DeleteDocApi = nullptr; 74 ResultNext NextApi = nullptr; 75 ResultPrev PrevApi = nullptr; 76 GetValue GetValueApi = nullptr; 77 Fetch FetchApi = nullptr; 78 FreeValue FreeValueApi = nullptr; 79 FreeResultSet FreeResultSetApi = nullptr; 80 KVPut KVPutApi = nullptr; 81 KVGet KVGetApi = nullptr; 82 KVDel KVDelApi = nullptr; 83 KVScan KVScanApi = nullptr; 84 KVFilter KVFilterApi = nullptr; 85 KVGetSize KVGetSizeApi = nullptr; 86 GetItem GetItemApi = nullptr; 87 KVFreeItem KVFreeItemApi = nullptr; 88 KVBatchPrepare KVBatchPrepareApi = nullptr; 89 KVBatchPushback KVBatchPushbackApi = nullptr; 90 KVBatchDel KVBatchPutApi = nullptr; 91 KVBatchDel KVBatchDelApi = nullptr; 92 KVBatchDestroy KVBatchDestroyApi = nullptr; 93 }; 94 GRD_APIInfo *GetApiInfo(); 95 void GetApiInfoInstance(void); 96 void InitApiInfo(const char *configStr); 97 void UnloadApiInfo(GRD_APIInfo *GRD_DBApiInfo); 98 } // namespace DocumentDB 99 #endif // __cplusplus 100