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