couchbase 4.2.1 → 4.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CMakeLists.txt +1 -0
- package/deps/couchbase-cxx-client/.gitmodules +3 -0
- package/deps/couchbase-cxx-client/.idea/misc.xml +1 -0
- package/deps/couchbase-cxx-client/.idea/vcs.xml +1 -0
- package/deps/couchbase-cxx-client/CMakeLists.txt +11 -1
- package/deps/couchbase-cxx-client/README.md +3 -3
- package/deps/couchbase-cxx-client/cmake/CompilerWarnings.cmake +4 -1
- package/deps/couchbase-cxx-client/cmake/VersionInfo.cmake +13 -1
- package/deps/couchbase-cxx-client/cmake/build_version.hxx.in +1 -0
- package/deps/couchbase-cxx-client/core/cluster.hxx +15 -5
- package/deps/couchbase-cxx-client/core/impl/build_deferred_query_indexes.cxx +17 -6
- package/deps/couchbase-cxx-client/core/impl/cluster.cxx +1 -1
- package/deps/couchbase-cxx-client/core/impl/collection_query_index_manager.cxx +93 -0
- package/deps/couchbase-cxx-client/core/impl/configuration_profiles_registry.cxx +11 -0
- package/deps/couchbase-cxx-client/core/impl/create_query_index.cxx +119 -0
- package/deps/couchbase-cxx-client/core/impl/drop_query_index.cxx +108 -0
- package/deps/couchbase-cxx-client/core/impl/get.cxx +1 -1
- package/deps/couchbase-cxx-client/core/impl/get_all_query_indexes.cxx +76 -0
- package/deps/couchbase-cxx-client/core/impl/query.cxx +5 -7
- package/deps/couchbase-cxx-client/core/impl/watch_query_indexes.cxx +168 -0
- package/deps/couchbase-cxx-client/core/io/mcbp_session.cxx +15 -1
- package/deps/couchbase-cxx-client/core/logger/configuration.hxx +3 -0
- package/deps/couchbase-cxx-client/core/logger/level.hxx +21 -0
- package/deps/couchbase-cxx-client/core/logger/logger.hxx +4 -6
- package/deps/couchbase-cxx-client/core/meta/CMakeLists.txt +4 -2
- package/deps/couchbase-cxx-client/core/meta/features.hxx +31 -0
- package/deps/couchbase-cxx-client/core/meta/version.cxx +67 -5
- package/deps/couchbase-cxx-client/core/meta/version.hxx +12 -1
- package/deps/couchbase-cxx-client/core/metrics/CMakeLists.txt +4 -1
- package/deps/couchbase-cxx-client/core/metrics/logging_meter.cxx +46 -5
- package/deps/couchbase-cxx-client/core/metrics/logging_meter.hxx +10 -26
- package/deps/couchbase-cxx-client/core/operations/document_get_projected.cxx +3 -2
- package/deps/couchbase-cxx-client/core/operations/document_query.cxx +10 -12
- package/deps/couchbase-cxx-client/core/operations/document_query.hxx +1 -3
- package/deps/couchbase-cxx-client/core/operations/management/query_index_build.cxx +8 -14
- package/deps/couchbase-cxx-client/core/operations/management/query_index_build.hxx +2 -1
- package/deps/couchbase-cxx-client/core/operations/management/query_index_build_deferred.hxx +15 -8
- package/deps/couchbase-cxx-client/core/operations/management/query_index_create.cxx +7 -14
- package/deps/couchbase-cxx-client/core/operations/management/query_index_create.hxx +2 -0
- package/deps/couchbase-cxx-client/core/operations/management/query_index_drop.cxx +11 -16
- package/deps/couchbase-cxx-client/core/operations/management/query_index_drop.hxx +2 -0
- package/deps/couchbase-cxx-client/core/operations/management/query_index_get_all.cxx +8 -12
- package/deps/couchbase-cxx-client/core/operations/management/query_index_get_all.hxx +4 -3
- package/deps/couchbase-cxx-client/core/operations/management/query_index_get_all_deferred.cxx +21 -12
- package/deps/couchbase-cxx-client/core/operations/management/query_index_get_all_deferred.hxx +3 -2
- package/deps/couchbase-cxx-client/core/origin.hxx +1 -1
- package/deps/couchbase-cxx-client/core/platform/uuid.cc +1 -2
- package/deps/couchbase-cxx-client/core/protocol/cmd_hello.hxx +5 -1
- package/deps/couchbase-cxx-client/core/query_context.hxx +79 -0
- package/deps/couchbase-cxx-client/core/tracing/CMakeLists.txt +3 -1
- package/deps/couchbase-cxx-client/core/tracing/threshold_logging_tracer.cxx +19 -4
- package/deps/couchbase-cxx-client/core/tracing/threshold_logging_tracer.hxx +2 -2
- package/deps/couchbase-cxx-client/core/transactions/async_attempt_context.hxx +10 -4
- package/deps/couchbase-cxx-client/core/transactions/atr_cleanup_entry.cxx +52 -63
- package/deps/couchbase-cxx-client/core/transactions/attempt_context.hxx +8 -3
- package/deps/couchbase-cxx-client/core/transactions/attempt_context_impl.cxx +163 -126
- package/deps/couchbase-cxx-client/core/transactions/attempt_context_impl.hxx +24 -37
- package/deps/couchbase-cxx-client/core/transactions/forward_compat.hxx +4 -4
- package/deps/couchbase-cxx-client/core/transactions/internal/atr_cleanup_entry.hxx +51 -13
- package/deps/couchbase-cxx-client/core/transactions/internal/client_record.hxx +26 -1
- package/deps/couchbase-cxx-client/core/transactions/internal/doc_record.hxx +21 -0
- package/deps/couchbase-cxx-client/core/transactions/internal/logging.hxx +40 -18
- package/deps/couchbase-cxx-client/core/transactions/internal/transaction_context.hxx +5 -0
- package/deps/couchbase-cxx-client/core/transactions/result.hxx +26 -0
- package/deps/couchbase-cxx-client/core/transactions/staged_mutation.cxx +48 -47
- package/deps/couchbase-cxx-client/core/transactions/staged_mutation.hxx +6 -6
- package/deps/couchbase-cxx-client/core/transactions/transaction_context.cxx +33 -19
- package/deps/couchbase-cxx-client/core/transactions/transaction_get_result.hxx +18 -2
- package/deps/couchbase-cxx-client/core/transactions/transaction_links.hxx +25 -2
- package/deps/couchbase-cxx-client/core/transactions/transactions.cxx +4 -4
- package/deps/couchbase-cxx-client/core/transactions/transactions_cleanup.cxx +49 -56
- package/deps/couchbase-cxx-client/core/transactions/waitable_op_list.hxx +7 -7
- package/deps/couchbase-cxx-client/core/transactions.hxx +0 -12
- package/deps/couchbase-cxx-client/core/utils/binary.hxx +1 -1
- package/deps/couchbase-cxx-client/core/utils/keyspace.hxx +55 -0
- package/deps/couchbase-cxx-client/couchbase/build_query_index_options.hxx +12 -45
- package/deps/couchbase-cxx-client/couchbase/cluster.hxx +1 -1
- package/deps/couchbase-cxx-client/couchbase/cluster_options.hxx +6 -7
- package/deps/couchbase-cxx-client/couchbase/collection.hxx +8 -0
- package/deps/couchbase-cxx-client/couchbase/collection_query_index_manager.hxx +218 -0
- package/deps/couchbase-cxx-client/couchbase/configuration_profiles_registry.hxx +3 -0
- package/deps/couchbase-cxx-client/couchbase/create_primary_query_index_options.hxx +166 -0
- package/deps/couchbase-cxx-client/couchbase/create_query_index_options.hxx +172 -0
- package/deps/couchbase-cxx-client/couchbase/drop_primary_query_index_options.hxx +129 -0
- package/deps/couchbase-cxx-client/couchbase/drop_query_index_options.hxx +116 -0
- package/deps/couchbase-cxx-client/couchbase/fmt/cas.hxx +1 -1
- package/deps/couchbase-cxx-client/couchbase/fmt/query_scan_consistency.hxx +46 -0
- package/deps/couchbase-cxx-client/couchbase/fmt/query_status.hxx +70 -0
- package/deps/couchbase-cxx-client/couchbase/fmt/tls_verify_mode.hxx +46 -0
- package/deps/couchbase-cxx-client/couchbase/get_all_query_indexes_options.hxx +100 -0
- package/deps/couchbase-cxx-client/{core → couchbase}/management/query_index.hxx +2 -2
- package/deps/couchbase-cxx-client/couchbase/metrics/meter.hxx +16 -0
- package/deps/couchbase-cxx-client/couchbase/query_index_manager.hxx +178 -6
- package/deps/couchbase-cxx-client/couchbase/query_options.hxx +1 -18
- package/deps/couchbase-cxx-client/couchbase/scope.hxx +5 -2
- package/deps/couchbase-cxx-client/couchbase/tracing/request_tracer.hxx +16 -0
- package/deps/couchbase-cxx-client/couchbase/transactions/async_attempt_context.hxx +11 -4
- package/deps/couchbase-cxx-client/couchbase/transactions/attempt_context.hxx +5 -3
- package/deps/couchbase-cxx-client/couchbase/transactions/transaction_keyspace.hxx +16 -0
- package/deps/couchbase-cxx-client/couchbase/transactions/transaction_query_options.hxx +0 -6
- package/deps/couchbase-cxx-client/couchbase/watch_query_indexes_options.hxx +115 -0
- package/deps/couchbase-cxx-client/examples/minimal.cxx +3 -1
- package/deps/couchbase-cxx-client/test/test_integration_crud.cxx +72 -0
- package/deps/couchbase-cxx-client/test/test_integration_management.cxx +727 -310
- package/deps/couchbase-cxx-client/test/test_integration_query.cxx +4 -8
- package/deps/couchbase-cxx-client/test/test_integration_transcoders.cxx +14 -0
- package/deps/couchbase-cxx-client/test/test_transaction_transaction_public_blocking_api.cxx +34 -19
- package/deps/couchbase-cxx-client/test/test_unit_transaction_logging.cxx +66 -22
- package/deps/couchbase-cxx-client/test/test_unit_utils.cxx +51 -0
- package/deps/couchbase-cxx-client/test/tools/tool_kv_loader.cxx +2 -2
- package/deps/couchbase-cxx-client/test/utils/integration_test_guard.cxx +2 -0
- package/deps/couchbase-cxx-client/test/utils/wait_until.cxx +4 -4
- package/deps/couchbase-cxx-client/third_party/docopt/.travis.yml +103 -0
- package/deps/couchbase-cxx-client/third_party/docopt/CMakeLists.txt +129 -0
- package/deps/couchbase-cxx-client/third_party/docopt/LICENSE-Boost-1.0 +23 -0
- package/deps/couchbase-cxx-client/third_party/docopt/LICENSE-MIT +23 -0
- package/deps/couchbase-cxx-client/third_party/docopt/README.rst +479 -0
- package/deps/couchbase-cxx-client/third_party/docopt/docopt-config.cmake +1 -0
- package/deps/couchbase-cxx-client/third_party/docopt/docopt.cpp +687 -0
- package/deps/couchbase-cxx-client/third_party/docopt/docopt.h +98 -0
- package/deps/couchbase-cxx-client/third_party/docopt/docopt.pc.in +9 -0
- package/deps/couchbase-cxx-client/third_party/docopt/docopt_private.h +676 -0
- package/deps/couchbase-cxx-client/third_party/docopt/docopt_util.h +122 -0
- package/deps/couchbase-cxx-client/third_party/docopt/docopt_value.h +341 -0
- package/deps/couchbase-cxx-client/third_party/docopt/examples/naval_fate.cpp +36 -0
- package/deps/couchbase-cxx-client/third_party/docopt/main.cpp +16 -0
- package/deps/couchbase-cxx-client/third_party/docopt/run_testcase.cpp +40 -0
- package/deps/couchbase-cxx-client/third_party/docopt/run_tests.py +72 -0
- package/deps/couchbase-cxx-client/third_party/docopt/testcases.docopt +957 -0
- package/deps/couchbase-cxx-client/tools/CMakeLists.txt +14 -0
- package/deps/couchbase-cxx-client/tools/cbc.cxx +65 -0
- package/deps/couchbase-cxx-client/tools/command.hxx +31 -0
- package/deps/couchbase-cxx-client/tools/command_registry.cxx +43 -0
- package/deps/couchbase-cxx-client/tools/command_registry.hxx +39 -0
- package/deps/couchbase-cxx-client/tools/get.cxx +267 -0
- package/deps/couchbase-cxx-client/tools/get.hxx +26 -0
- package/deps/couchbase-cxx-client/tools/query.cxx +441 -0
- package/deps/couchbase-cxx-client/tools/query.hxx +26 -0
- package/deps/couchbase-cxx-client/tools/utils.cxx +418 -0
- package/deps/couchbase-cxx-client/tools/utils.hxx +150 -0
- package/deps/couchbase-cxx-client/tools/version.cxx +82 -0
- package/deps/couchbase-cxx-client/tools/version.hxx +26 -0
- package/dist/authenticators.d.ts +2 -2
- package/dist/authenticators.js +1 -2
- package/dist/binding.d.ts +32 -16
- package/dist/cluster.js +14 -7
- package/dist/collection.d.ts +6 -0
- package/dist/collection.js +8 -0
- package/dist/queryexecutor.js +1 -1
- package/dist/queryindexmanager.d.ts +100 -4
- package/dist/queryindexmanager.js +344 -118
- package/dist/transactions.js +0 -2
- package/package.json +1 -1
- package/src/connection.cpp +2 -0
- package/src/connection.hpp +1 -0
- package/src/connection_autogen.cpp +16 -0
- package/src/jstocbpp_autogen.hpp +93 -23
- package/src/jstocbpp_basic.hpp +24 -0
- package/src/jstocbpp_transactions.hpp +0 -8
- package/tools/gen-bindings-js.js +1 -0
- package/tools/gen-bindings-json.py +4 -2
- package/deps/couchbase-cxx-client/core/transactions/logging.cxx +0 -107
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
add_executable(
|
|
2
|
+
cbc
|
|
3
|
+
cbc.cxx
|
|
4
|
+
utils.cxx
|
|
5
|
+
command_registry.cxx
|
|
6
|
+
get.cxx
|
|
7
|
+
query.cxx
|
|
8
|
+
version.cxx)
|
|
9
|
+
target_include_directories(cbc PUBLIC ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/private)
|
|
10
|
+
target_link_libraries(
|
|
11
|
+
cbc
|
|
12
|
+
${CMAKE_THREAD_LIBS_INIT}
|
|
13
|
+
couchbase_cxx_client
|
|
14
|
+
docopt)
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2023-Present Couchbase, Inc.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
#include "command_registry.hxx"
|
|
19
|
+
#include "utils.hxx"
|
|
20
|
+
|
|
21
|
+
static constexpr auto* USAGE =
|
|
22
|
+
R"(Talk to Couchbase Server.
|
|
23
|
+
|
|
24
|
+
Usage:
|
|
25
|
+
cbc <command> [<argument>...]
|
|
26
|
+
cbc (-h|--help)
|
|
27
|
+
cbc --version
|
|
28
|
+
|
|
29
|
+
Available commands:
|
|
30
|
+
|
|
31
|
+
version Display version information.
|
|
32
|
+
get Retrieve document from the server.
|
|
33
|
+
query Perform N1QL query.
|
|
34
|
+
|
|
35
|
+
Options:
|
|
36
|
+
-h --help Show this screen.
|
|
37
|
+
--version Show version.
|
|
38
|
+
)";
|
|
39
|
+
|
|
40
|
+
int
|
|
41
|
+
main(int argc, const char** argv)
|
|
42
|
+
{
|
|
43
|
+
cbc::command_registry commands;
|
|
44
|
+
try {
|
|
45
|
+
std::vector<std::string> args{ argv + 1, argv + argc };
|
|
46
|
+
auto options = cbc::parse_options(USAGE, args, true);
|
|
47
|
+
|
|
48
|
+
if (options["--help"].asBool()) {
|
|
49
|
+
fmt::print(stdout, USAGE);
|
|
50
|
+
return 0;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
auto command_name = options["<command>"].asString();
|
|
54
|
+
if (auto command = commands.get(command_name); command) {
|
|
55
|
+
command->execute(args);
|
|
56
|
+
return 0;
|
|
57
|
+
}
|
|
58
|
+
fmt::print(stderr, "Error: unrecognized command 'cbc {}'\n", command_name);
|
|
59
|
+
fmt::print(stderr, "Try 'cbc --help' for more information\n", command_name);
|
|
60
|
+
return 1;
|
|
61
|
+
} catch (const docopt::DocoptArgumentError&) {
|
|
62
|
+
fmt::print(stderr, "Error: missing command 'cbc <command>'\n");
|
|
63
|
+
return 1;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2023-Present Couchbase, Inc.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
#pragma once
|
|
19
|
+
|
|
20
|
+
#include <string>
|
|
21
|
+
#include <vector>
|
|
22
|
+
|
|
23
|
+
namespace cbc
|
|
24
|
+
{
|
|
25
|
+
class command
|
|
26
|
+
{
|
|
27
|
+
public:
|
|
28
|
+
virtual ~command() = default;
|
|
29
|
+
virtual void execute(const std::vector<std::string>& argv) = 0;
|
|
30
|
+
};
|
|
31
|
+
} // namespace cbc
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2023-Present Couchbase, Inc.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
#include "command_registry.hxx"
|
|
19
|
+
|
|
20
|
+
#include "get.hxx"
|
|
21
|
+
#include "query.hxx"
|
|
22
|
+
#include "version.hxx"
|
|
23
|
+
|
|
24
|
+
namespace cbc
|
|
25
|
+
{
|
|
26
|
+
command_registry::command_registry()
|
|
27
|
+
: commands_{
|
|
28
|
+
{ "version", std::make_shared<cbc::version>() },
|
|
29
|
+
{ "get", std::make_shared<cbc::get>() },
|
|
30
|
+
{ "query", std::make_shared<cbc::query>() },
|
|
31
|
+
}
|
|
32
|
+
{
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
auto
|
|
36
|
+
command_registry::get(const std::string& name) -> std::shared_ptr<command>
|
|
37
|
+
{
|
|
38
|
+
if (auto cmd = commands_.find(name); cmd != commands_.end()) {
|
|
39
|
+
return cmd->second;
|
|
40
|
+
}
|
|
41
|
+
return nullptr;
|
|
42
|
+
}
|
|
43
|
+
} // namespace cbc
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2023-Present Couchbase, Inc.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
#pragma once
|
|
19
|
+
|
|
20
|
+
#include "command.hxx"
|
|
21
|
+
|
|
22
|
+
#include <map>
|
|
23
|
+
#include <memory>
|
|
24
|
+
#include <string>
|
|
25
|
+
|
|
26
|
+
namespace cbc
|
|
27
|
+
{
|
|
28
|
+
class command_registry
|
|
29
|
+
{
|
|
30
|
+
public:
|
|
31
|
+
command_registry();
|
|
32
|
+
|
|
33
|
+
auto get(const std::string& name) -> std::shared_ptr<command>;
|
|
34
|
+
|
|
35
|
+
private:
|
|
36
|
+
std::map<std::string, std::shared_ptr<command>, std::less<>> commands_;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
} // namespace cbc
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2023-Present Couchbase, Inc.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
#include "get.hxx"
|
|
19
|
+
#include "utils.hxx"
|
|
20
|
+
|
|
21
|
+
#include <core/logger/logger.hxx>
|
|
22
|
+
#include <couchbase/cluster.hxx>
|
|
23
|
+
#include <couchbase/codec/raw_binary_transcoder.hxx>
|
|
24
|
+
#include <couchbase/fmt/cas.hxx>
|
|
25
|
+
|
|
26
|
+
#include <asio/io_context.hpp>
|
|
27
|
+
#include <fmt/chrono.h>
|
|
28
|
+
#include <spdlog/fmt/bin_to_hex.h>
|
|
29
|
+
#include <tao/json.hpp>
|
|
30
|
+
|
|
31
|
+
namespace cbc
|
|
32
|
+
{
|
|
33
|
+
namespace
|
|
34
|
+
{
|
|
35
|
+
static auto
|
|
36
|
+
usage() -> std::string
|
|
37
|
+
{
|
|
38
|
+
static const std::string default_bucket_name{ "default" };
|
|
39
|
+
|
|
40
|
+
static const std::string usage_string = fmt::format(
|
|
41
|
+
R"(Display version information.
|
|
42
|
+
|
|
43
|
+
Usage:
|
|
44
|
+
cbc get [options] <id>...
|
|
45
|
+
cbc get [options] --project=STRING... <id>...
|
|
46
|
+
cbc get (-h|--help)
|
|
47
|
+
|
|
48
|
+
Options:
|
|
49
|
+
-h --help Show this screen.
|
|
50
|
+
--bucket-name=STRING Name of the bucket. [default: {bucket_name}]
|
|
51
|
+
--scope-name=STRING Name of the scope. [default: {scope_name}]
|
|
52
|
+
--collection-name=STRING Name of the collection. [default: {collection_name}]
|
|
53
|
+
--inlined-keyspace Extract bucket, scope, collection and key from the IDs (captures will be done with /^(.*?):(.*?)\.(.*?):(.*)$/).
|
|
54
|
+
--with-expiry Return document expiry time, if set.
|
|
55
|
+
--project=STRING Return only part of the document, that corresponds given JSON-pointer (could be used multiple times, up to {max_projections}).
|
|
56
|
+
--hexdump Print value using hexdump encoding (safe for binary data on STDOUT).
|
|
57
|
+
--pretty-json Try to pretty-print as JSON value (prints AS-IS is the document is not a JSON).
|
|
58
|
+
--json-lines Use JSON Lines format (https://jsonlines.org/) to print results.
|
|
59
|
+
|
|
60
|
+
{logger_options}{cluster_options}
|
|
61
|
+
)",
|
|
62
|
+
fmt::arg("bucket_name", default_bucket_name),
|
|
63
|
+
fmt::arg("scope_name", couchbase::scope::default_name),
|
|
64
|
+
fmt::arg("collection_name", couchbase::collection::default_name),
|
|
65
|
+
fmt::arg("logger_options", usage_block_for_logger()),
|
|
66
|
+
fmt::arg("cluster_options", usage_block_for_cluster_options()),
|
|
67
|
+
fmt::arg("max_projections", couchbase::get_options::maximum_number_of_projections));
|
|
68
|
+
|
|
69
|
+
return usage_string;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
struct command_options {
|
|
73
|
+
std::string bucket_name;
|
|
74
|
+
std::string scope_name;
|
|
75
|
+
std::string collection_name;
|
|
76
|
+
std::vector<std::string> projections{};
|
|
77
|
+
bool with_expiry{ false };
|
|
78
|
+
bool inlined_keyspace{ false };
|
|
79
|
+
bool hexdump{ false };
|
|
80
|
+
bool pretty_json{ false };
|
|
81
|
+
bool json_lines{ false };
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
static void
|
|
85
|
+
print_result_json_line(const std::string& bucket_name,
|
|
86
|
+
const std::string& scope_name,
|
|
87
|
+
const std::string& collection_name,
|
|
88
|
+
const std::string& document_id,
|
|
89
|
+
const couchbase::key_value_error_context& ctx,
|
|
90
|
+
const couchbase::get_result& resp)
|
|
91
|
+
{
|
|
92
|
+
tao::json::value line = tao::json::empty_object;
|
|
93
|
+
tao::json::value meta = {
|
|
94
|
+
{ "bucket_name", bucket_name },
|
|
95
|
+
{ "scope_name", scope_name },
|
|
96
|
+
{ "collection_name", collection_name },
|
|
97
|
+
{ "document_id", document_id },
|
|
98
|
+
};
|
|
99
|
+
if (ctx.ec()) {
|
|
100
|
+
tao::json::value error = {
|
|
101
|
+
{ "code", ctx.ec().value() },
|
|
102
|
+
{ "message", ctx.ec().message() },
|
|
103
|
+
};
|
|
104
|
+
if (auto ext = ctx.extended_error_info(); ext.has_value()) {
|
|
105
|
+
error["ref"] = ext->reference();
|
|
106
|
+
error["ctx"] = ext->context();
|
|
107
|
+
}
|
|
108
|
+
line["error"] = error;
|
|
109
|
+
} else {
|
|
110
|
+
auto [value, flags] = resp.content_as<cbc::passthrough_transcoder>();
|
|
111
|
+
meta["cas"] = fmt::format("0x{}", resp.cas());
|
|
112
|
+
meta["flags"] = flags;
|
|
113
|
+
if (const auto& expiry = resp.expiry_time(); expiry) {
|
|
114
|
+
meta["expiry_time"] = fmt::format("{}", expiry.value());
|
|
115
|
+
}
|
|
116
|
+
try {
|
|
117
|
+
line["json"] = couchbase::core::utils::json::parse_binary(value);
|
|
118
|
+
} catch (const tao::pegtl::parse_error&) {
|
|
119
|
+
line["base64"] = value;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
line["meta"] = meta;
|
|
123
|
+
fmt::print(stdout, "{}\n", tao::json::to_string<tao::json::events::binary_to_base64>(line));
|
|
124
|
+
(void)fflush(stdout);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
static void
|
|
128
|
+
print_result(const std::string& bucket_name,
|
|
129
|
+
const std::string& scope_name,
|
|
130
|
+
const std::string& collection_name,
|
|
131
|
+
const std::string& document_id,
|
|
132
|
+
const couchbase::key_value_error_context& ctx,
|
|
133
|
+
const couchbase::get_result& resp,
|
|
134
|
+
const command_options& cmd_options)
|
|
135
|
+
{
|
|
136
|
+
const std::string prefix = fmt::format("bucket: {}, collection: {}.{}, id: {}", bucket_name, scope_name, collection_name, document_id);
|
|
137
|
+
(void)fflush(stderr);
|
|
138
|
+
if (ctx.ec()) {
|
|
139
|
+
if (auto ext = ctx.extended_error_info(); ext.has_value()) {
|
|
140
|
+
fmt::print(stderr, "{}, error: {} (ref: {}, ctx: {})\n", prefix, ctx.ec().message(), ext->reference(), ext->context());
|
|
141
|
+
} else {
|
|
142
|
+
fmt::print(stderr, "{}, error: {}\n", prefix, ctx.ec().message());
|
|
143
|
+
}
|
|
144
|
+
} else {
|
|
145
|
+
auto [value, flags] = resp.content_as<cbc::passthrough_transcoder>();
|
|
146
|
+
if (resp.expiry_time()) {
|
|
147
|
+
fmt::print(stderr,
|
|
148
|
+
"{}, size: {}, CAS: 0x{}, flags: 0x{:08x}, expiry: {}\n",
|
|
149
|
+
prefix,
|
|
150
|
+
value.size(),
|
|
151
|
+
resp.cas(),
|
|
152
|
+
flags,
|
|
153
|
+
resp.expiry_time().value());
|
|
154
|
+
} else {
|
|
155
|
+
fmt::print(stderr, "{}, size: {}, CAS: 0x{}, flags: 0x{:08x}\n", prefix, value.size(), resp.cas(), flags);
|
|
156
|
+
}
|
|
157
|
+
(void)fflush(stderr);
|
|
158
|
+
(void)fflush(stdout);
|
|
159
|
+
if (cmd_options.hexdump) {
|
|
160
|
+
auto hex = fmt::format("{:a}", spdlog::to_hex(value));
|
|
161
|
+
fmt::print(stdout, "{}\n", std::string_view(hex.data() + 1, hex.size() - 1));
|
|
162
|
+
} else if (cmd_options.pretty_json) {
|
|
163
|
+
try {
|
|
164
|
+
auto json = couchbase::core::utils::json::parse_binary(value);
|
|
165
|
+
fmt::print(stdout, "{}\n", tao::json::to_string(json, 2));
|
|
166
|
+
} catch (const tao::pegtl::parse_error&) {
|
|
167
|
+
fmt::print(stdout, "{}\n", std::string_view(reinterpret_cast<const char*>(value.data()), value.size()));
|
|
168
|
+
}
|
|
169
|
+
} else {
|
|
170
|
+
fmt::print(stdout, "{}\n", std::string_view(reinterpret_cast<const char*>(value.data()), value.size()));
|
|
171
|
+
}
|
|
172
|
+
(void)fflush(stdout);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
static void
|
|
177
|
+
do_work(const std::string& connection_string,
|
|
178
|
+
couchbase::cluster_options& cluster_options,
|
|
179
|
+
const std::vector<std::string>& ids,
|
|
180
|
+
const command_options& cmd_options)
|
|
181
|
+
{
|
|
182
|
+
asio::io_context io;
|
|
183
|
+
auto guard = asio::make_work_guard(io);
|
|
184
|
+
std::thread io_thread([&io]() { io.run(); });
|
|
185
|
+
|
|
186
|
+
auto [cluster, ec] = couchbase::cluster::connect(io, connection_string, cluster_options).get();
|
|
187
|
+
if (ec) {
|
|
188
|
+
throw std::system_error(ec);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
couchbase::get_options get_options{};
|
|
192
|
+
if (cmd_options.with_expiry) {
|
|
193
|
+
get_options.with_expiry(true);
|
|
194
|
+
}
|
|
195
|
+
if (!cmd_options.projections.empty()) {
|
|
196
|
+
get_options.project(cmd_options.projections);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
for (const auto& id : ids) {
|
|
200
|
+
auto bucket_name = cmd_options.bucket_name;
|
|
201
|
+
auto scope_name = cmd_options.scope_name;
|
|
202
|
+
auto collection_name = cmd_options.collection_name;
|
|
203
|
+
auto document_id = id;
|
|
204
|
+
|
|
205
|
+
if (cmd_options.inlined_keyspace) {
|
|
206
|
+
if (auto keyspace_with_id = extract_inlined_keyspace(id); keyspace_with_id) {
|
|
207
|
+
bucket_name = keyspace_with_id->bucket_name;
|
|
208
|
+
scope_name = keyspace_with_id->scope_name;
|
|
209
|
+
collection_name = keyspace_with_id->collection_name;
|
|
210
|
+
document_id = keyspace_with_id->id;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
auto collection = cluster.bucket(bucket_name).scope(scope_name).collection(collection_name);
|
|
215
|
+
|
|
216
|
+
auto [ctx, resp] = collection.get(document_id, get_options).get();
|
|
217
|
+
if (cmd_options.json_lines) {
|
|
218
|
+
print_result_json_line(bucket_name, scope_name, collection_name, document_id, ctx, resp);
|
|
219
|
+
} else {
|
|
220
|
+
print_result(bucket_name, scope_name, collection_name, document_id, ctx, resp, cmd_options);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
cluster.close();
|
|
225
|
+
guard.reset();
|
|
226
|
+
|
|
227
|
+
io_thread.join();
|
|
228
|
+
}
|
|
229
|
+
} // namespace
|
|
230
|
+
|
|
231
|
+
void
|
|
232
|
+
cbc::get::execute(const std::vector<std::string>& argv)
|
|
233
|
+
{
|
|
234
|
+
try {
|
|
235
|
+
|
|
236
|
+
auto options = cbc::parse_options(usage(), argv);
|
|
237
|
+
if (options["--help"].asBool()) {
|
|
238
|
+
fmt::print(stdout, usage());
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
cbc::apply_logger_options(options);
|
|
243
|
+
|
|
244
|
+
couchbase::cluster_options cluster_options{ cbc::default_cluster_options() };
|
|
245
|
+
std::string connection_string{ cbc::default_connection_string() };
|
|
246
|
+
cbc::fill_cluster_options(options, cluster_options, connection_string);
|
|
247
|
+
|
|
248
|
+
command_options cmd_options{};
|
|
249
|
+
cmd_options.bucket_name = options["--bucket-name"].asString();
|
|
250
|
+
cmd_options.scope_name = options["--scope-name"].asString();
|
|
251
|
+
cmd_options.collection_name = options["--collection-name"].asString();
|
|
252
|
+
cmd_options.inlined_keyspace = options["--inlined-keyspace"].asBool();
|
|
253
|
+
cmd_options.with_expiry = options["--with-expiry"].asBool();
|
|
254
|
+
cmd_options.hexdump = options["--hexdump"].asBool();
|
|
255
|
+
cmd_options.pretty_json = options["--pretty-json"].asBool();
|
|
256
|
+
cmd_options.projections = options["--project"].asStringList();
|
|
257
|
+
cmd_options.json_lines = options["--json-lines"].asBool();
|
|
258
|
+
auto ids{ options["<id>"].asStringList() };
|
|
259
|
+
|
|
260
|
+
do_work(connection_string, cluster_options, ids, cmd_options);
|
|
261
|
+
} catch (const docopt::DocoptArgumentError& e) {
|
|
262
|
+
fmt::print(stderr, "Error: {}\n", e.what());
|
|
263
|
+
} catch (const std::system_error& e) {
|
|
264
|
+
fmt::print(stderr, "Error: {}\n", e.what());
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
} // namespace cbc
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2023-Present Couchbase, Inc.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
#include "command.hxx"
|
|
19
|
+
|
|
20
|
+
namespace cbc
|
|
21
|
+
{
|
|
22
|
+
class get : public command
|
|
23
|
+
{
|
|
24
|
+
void execute(const std::vector<std::string>& argv);
|
|
25
|
+
};
|
|
26
|
+
} // namespace cbc
|