• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "grd_kv/grd_kv_api.h"
16 
17 #include "grd_api_manager.h"
18 #include "grd_base/grd_error.h"
19 #include "grd_resultset_inner.h"
20 #include "grd_type_inner.h"
21 #include "rd_log_print.h"
22 using namespace DocumentDB;
23 
24 static GRD_APIInfo *GRD_KVApiInfo = GetApiInfo();
25 
GRD_KVPut(GRD_DB * db,const char * collectionName,const GRD_KVItemT * key,const GRD_KVItemT * value)26 GRD_API int32_t GRD_KVPut(GRD_DB *db, const char *collectionName, const GRD_KVItemT *key, const GRD_KVItemT *value)
27 {
28     if (GRD_KVApiInfo->KVPutApi == nullptr) {
29         return GRD_INNER_ERR;
30     }
31     return GRD_KVApiInfo->KVPutApi(db, collectionName, key, value);
32 }
33 
GRD_KVGet(GRD_DB * db,const char * collectionName,const GRD_KVItemT * key,const GRD_KVItemT * value)34 GRD_API int32_t GRD_KVGet(GRD_DB *db, const char *collectionName, const GRD_KVItemT *key, const GRD_KVItemT *value)
35 {
36     if (GRD_KVApiInfo->KVGetApi == nullptr) {
37         return GRD_INNER_ERR;
38     }
39     return GRD_KVApiInfo->KVGetApi(db, collectionName, key, value);
40 }
41 
GRD_KVDel(GRD_DB * db,const char * collectionName,const GRD_KVItemT * key)42 GRD_API int32_t GRD_KVDel(GRD_DB *db, const char *collectionName, const GRD_KVItemT *key)
43 {
44     if (GRD_KVApiInfo->KVDelApi == nullptr) {
45         return GRD_INNER_ERR;
46     }
47     return GRD_KVApiInfo->KVDelApi(db, collectionName, key);
48 }
49 
GRD_KVScan(GRD_DB * db,const char * collectionName,const GRD_KVItemT * key,GRD_KvScanModeE mode,GRD_ResultSet ** resultSet)50 GRD_API int32_t GRD_KVScan(GRD_DB *db, const char *collectionName, const GRD_KVItemT *key, GRD_KvScanModeE mode,
51     GRD_ResultSet **resultSet)
52 {
53     if (GRD_KVApiInfo->KVScanApi == nullptr) {
54         return GRD_INNER_ERR;
55     }
56     return GRD_KVApiInfo->KVScanApi(db, collectionName, key, mode, resultSet);
57 }
58 
GRD_KVFilter(GRD_DB * db,const char * collectionName,const GRD_FilterOptionT * scanParams,GRD_ResultSet ** resultSet)59 GRD_API int32_t GRD_KVFilter(GRD_DB *db, const char *collectionName, const GRD_FilterOptionT *scanParams,
60     GRD_ResultSet **resultSet)
61 {
62     if (GRD_KVApiInfo->KVFilterApi == nullptr) {
63         return GRD_INNER_ERR;
64     }
65     return GRD_KVApiInfo->KVFilterApi(db, collectionName, scanParams, resultSet);
66 }
67 
GRD_KVGetSize(GRD_ResultSet * resultSet,uint32_t * keyLen,uint32_t * valueLen)68 GRD_API int32_t GRD_KVGetSize(GRD_ResultSet *resultSet, uint32_t *keyLen, uint32_t *valueLen)
69 {
70     if (GRD_KVApiInfo->KVGetSizeApi == nullptr) {
71         return GRD_INNER_ERR;
72     }
73     return GRD_KVApiInfo->KVGetSizeApi(resultSet, keyLen, valueLen);
74 }
75 
GRD_GetItem(GRD_ResultSet * resultSet,void * key,void * value)76 GRD_API int32_t GRD_GetItem(GRD_ResultSet *resultSet, void *key, void *value)
77 {
78     if (GRD_KVApiInfo->GetItemApi == nullptr) {
79         return GRD_INNER_ERR;
80     }
81     return GRD_KVApiInfo->GetItemApi(resultSet, key, value);
82 }
83 
GRD_KVFreeItem(GRD_KVItemT * item)84 GRD_API int32_t GRD_KVFreeItem(GRD_KVItemT *item)
85 {
86     if (GRD_KVApiInfo->KVFreeItemApi == nullptr) {
87         return GRD_INNER_ERR;
88     }
89     return GRD_KVApiInfo->KVFreeItemApi(item);
90 }
91 
GRD_KVBatchPrepare(uint16_t itemNum,GRD_KVBatchT ** batch)92 GRD_API int32_t GRD_KVBatchPrepare(uint16_t itemNum, GRD_KVBatchT **batch)
93 {
94     if (GRD_KVApiInfo->KVBatchPrepareApi == nullptr) {
95         return GRD_INNER_ERR;
96     }
97     return GRD_KVApiInfo->KVBatchPrepareApi(itemNum, batch);
98 }
99 
GRD_KVBatchPushback(const void * key,uint32_t keyLen,const void * data,uint32_t dataLen,GRD_KVBatchT * batch)100 GRD_API int32_t GRD_KVBatchPushback(const void *key, uint32_t keyLen, const void *data, uint32_t dataLen,
101     GRD_KVBatchT *batch)
102 {
103     if (GRD_KVApiInfo->KVBatchPushbackApi == nullptr) {
104         return GRD_INNER_ERR;
105     }
106     return GRD_KVApiInfo->KVBatchPushbackApi(key, keyLen, data, dataLen, batch);
107 }
108 
GRD_KVBatchPut(GRD_DB * db,const char * collectionName,GRD_KVBatchT * batch)109 GRD_API int32_t GRD_KVBatchPut(GRD_DB *db, const char *collectionName, GRD_KVBatchT *batch)
110 {
111     if (GRD_KVApiInfo->KVBatchPutApi == nullptr) {
112         return GRD_INNER_ERR;
113     }
114     return GRD_KVApiInfo->KVBatchPutApi(db, collectionName, batch);
115 }
116 
GRD_KVBatchDel(GRD_DB * db,const char * collectionName,GRD_KVBatchT * batch)117 GRD_API int32_t GRD_KVBatchDel(GRD_DB *db, const char *collectionName, GRD_KVBatchT *batch)
118 {
119     if (GRD_KVApiInfo->KVBatchDelApi == nullptr) {
120         return GRD_INNER_ERR;
121     }
122     return GRD_KVApiInfo->KVBatchDelApi(db, collectionName, batch);
123 }
124 
GRD_KVBatchDestroy(GRD_KVBatchT * batch)125 GRD_API int32_t GRD_KVBatchDestroy(GRD_KVBatchT *batch)
126 {
127     if (GRD_KVApiInfo->KVBatchDestroyApi == nullptr) {
128         return GRD_INNER_ERR;
129     }
130     return GRD_KVApiInfo->KVBatchDestroyApi(batch);
131 }
132