From 9fd88df940c1946ec4ef0e0d967f8ee343177fb8 Mon Sep 17 00:00:00 2001 From: lianhuix Date: Sat, 18 Feb 2023 07:27:46 +0000 Subject: [PATCH 1/2] Init Document DB Signed-off-by: lianhuix --- frameworks/libs/documentdb/README.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 frameworks/libs/documentdb/README.md diff --git a/frameworks/libs/documentdb/README.md b/frameworks/libs/documentdb/README.md new file mode 100644 index 00000000000..1d777fec2bf --- /dev/null +++ b/frameworks/libs/documentdb/README.md @@ -0,0 +1 @@ +# Document DB -- Gitee From b728e48b56d3a4de00536533ce14c11c28cf12ee Mon Sep 17 00:00:00 2001 From: lianhuix Date: Sat, 18 Feb 2023 08:54:39 +0000 Subject: [PATCH 2/2] Add json doc db api Signed-off-by: lianhuix --- .../documentdb/include/nb_base/nb_db_api.h | 32 ++++++++++++ .../documentdb/include/nb_base/nb_error.h | 51 +++++++++++++++++++ .../include/nb_base/nb_resultset_api.h | 36 +++++++++++++ .../include/nb_base/nb_type_export.h | 33 ++++++++++++ .../include/nb_document/nb_document_api.h | 43 ++++++++++++++++ 5 files changed, 195 insertions(+) create mode 100644 frameworks/libs/documentdb/include/nb_base/nb_db_api.h create mode 100644 frameworks/libs/documentdb/include/nb_base/nb_error.h create mode 100644 frameworks/libs/documentdb/include/nb_base/nb_resultset_api.h create mode 100644 frameworks/libs/documentdb/include/nb_base/nb_type_export.h create mode 100644 frameworks/libs/documentdb/include/nb_document/nb_document_api.h diff --git a/frameworks/libs/documentdb/include/nb_base/nb_db_api.h b/frameworks/libs/documentdb/include/nb_base/nb_db_api.h new file mode 100644 index 00000000000..4673c4de812 --- /dev/null +++ b/frameworks/libs/documentdb/include/nb_base/nb_db_api.h @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2023 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef NATURALBASE_NB_DB_API_H +#define NATURALBASE_NB_DB_API_H + +#include "nb_type_export.h" + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +int NB_DBOpen(const char *dbPath, const char *configStr, unsigned int flags, NB_DB **db); + +int NB_DBClose(NB_DB *db, unsigned int flags); + +#ifdef __cplusplus +} +#endif // __cplusplus +#endif // NATURALBASE_NB_DB_API_H \ No newline at end of file diff --git a/frameworks/libs/documentdb/include/nb_base/nb_error.h b/frameworks/libs/documentdb/include/nb_base/nb_error.h new file mode 100644 index 00000000000..fba4f5a30f2 --- /dev/null +++ b/frameworks/libs/documentdb/include/nb_base/nb_error.h @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2023 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef NATURALBASE_NB_ERROR_H +#define NATURALBASE_NB_ERROR_H + +#include "nb_type_export.h" + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +#define NB_OK 0 + +#define NB_NOT_SUPPORT (-1000) +#define NB_OVER_LIMIT (-2000) +#define NB_INVALID_ARGS (-3000) +#define NB_SYSTEM_ERR (-4000) +#define NB_NO_DATA (-11000) +#define NB_FAILED_MEMORY_ALLOCATE (-13000) +#define NB_FAILED_MEMORY_RELEASE (-14000) +#define NB_INVALID_FORMAT (-37000) + +#define NB_FIELD_NOT_FOUND (-5003002) +#define NB_FIELD_TYPE_NOT_MATCH (-5003003) +#define NB_LARGE_JSON_NEST (-5003004) + +#define NB_UNVAILABLE_JSON_LIB (-5004001) + + +#define NB_COLLECTION_NOT_FOUND (-5011001) +#define NB_RECORD_NOT_FOUND (-5011002) + +#define NB_INVALID_JSON_FORMAT (-5037001) + +#ifdef __cplusplus +} +#endif // __cplusplus +#endif // NATURALBASE_NB_ERROR_H \ No newline at end of file diff --git a/frameworks/libs/documentdb/include/nb_base/nb_resultset_api.h b/frameworks/libs/documentdb/include/nb_base/nb_resultset_api.h new file mode 100644 index 00000000000..858f48c5909 --- /dev/null +++ b/frameworks/libs/documentdb/include/nb_base/nb_resultset_api.h @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2023 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef NATURALBASE_NB_RESULTSET_API_H +#define NATURALBASE_NB_RESULTSET_API_H + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +typedef struct NB_ResultSet NB_ResultSet; + +int NB_Next(NB_ResultSet *resultSet); + +int NB_GetValue(NB_ResultSet *resultSet, char **value); + +int NB_FreeValue(char *value); + +int NB_FreeResultSet(NB_ResultSet *resultSet); + +#ifdef __cplusplus +} +#endif // __cplusplus +#endif // NATURALBASE_NB_RESULTSET_API_H \ No newline at end of file diff --git a/frameworks/libs/documentdb/include/nb_base/nb_type_export.h b/frameworks/libs/documentdb/include/nb_base/nb_type_export.h new file mode 100644 index 00000000000..b0b547bfd08 --- /dev/null +++ b/frameworks/libs/documentdb/include/nb_base/nb_type_export.h @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2023 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef NATURALBASE_NB_TYPE_EXPORT_H +#define NATURALBASE_NB_TYPE_EXPORT_H + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +typedef struct NB_DB NB_DB; + +typedef struct Query { + const char *filter; + const char *projection; +} Query; + +#ifdef __cplusplus +} +#endif // __cplusplus +#endif // NATURALBASE_NB_TYPE_EXPORT_H \ No newline at end of file diff --git a/frameworks/libs/documentdb/include/nb_document/nb_document_api.h b/frameworks/libs/documentdb/include/nb_document/nb_document_api.h new file mode 100644 index 00000000000..feebe183984 --- /dev/null +++ b/frameworks/libs/documentdb/include/nb_document/nb_document_api.h @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2023 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef NATURALBASE_NB_DOCUMENT_API_H +#define NATURALBASE_NB_DOCUMENT_API_H + +#include "nb_type_export.h" +#include "nb_result_api.h" + +#ifdef __cplusplus +extern "C" { +#endif + +int NB_CreateCollection(NB_DB *db, const char *collectionName, const char *optionStr, unsigned int flags); + +int NB_DropCollection(NB_DB *db, const char *collectionName, unsigned int flags); + +int NB_InsertDoc(NB_DB *db, const char *collectionName, const char *document, unsigned int flags); + +int NB_FindDoc(NB_DB *db, const char *collectionName, Query query, unsigned int flags, NB_ResultSet **resultSet); + +int NB_UpdateDoc(NB_DB *db, const char *collectionName, const char *filter, const char *update, unsigned int flags); + +int NB_UpSertDoc(NB_DB *db, const char *collectionName, const char *filter, const char *document, unsigned int flags); + +int NB_DeleteDoc(NB_DB *db, const char *collectionName, const char *filter, unsigned int flags); + +#ifdef __cplusplus +} +#endif +#endif // NATURALBASE_NB_DOCUMENT_API_H \ No newline at end of file -- Gitee