Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions core/impl/query_index_manager.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class query_index_manager_impl : public std::enable_shared_from_this<query_index
const std::string& scope_name,
const std::string& collection_name,
std::string index_name,
std::vector<std::string> fields,
std::vector<std::string> keys,
const create_query_index_options::built& options,
create_query_index_handler&& handler) const
{
Expand All @@ -225,7 +225,7 @@ class query_index_manager_impl : public std::enable_shared_from_this<query_index
scope_name,
collection_name,
std::move(index_name),
std::move(fields),
std::move(keys),
{},
false /* is_primary */,
options.ignore_if_exists,
Expand Down Expand Up @@ -521,22 +521,22 @@ collection_query_index_manager::get_all_indexes(const get_all_query_indexes_opti

void
collection_query_index_manager::create_index(std::string index_name,
std::vector<std::string> fields,
std::vector<std::string> keys,
const create_query_index_options& options,
create_query_index_handler&& handler) const
{
return impl_->create_index(
bucket_name_, scope_name_, collection_name_, std::move(index_name), std::move(fields), options.build(), std::move(handler));
bucket_name_, scope_name_, collection_name_, std::move(index_name), std::move(keys), options.build(), std::move(handler));
}

auto
collection_query_index_manager::create_index(std::string index_name,
std::vector<std::string> fields,
std::vector<std::string> keys,
const create_query_index_options& options) const -> std::future<manager_error_context>
{
auto barrier = std::make_shared<std::promise<manager_error_context>>();
auto future = barrier->get_future();
create_index(std::move(index_name), std::move(fields), options, [barrier](auto ctx) { barrier->set_value(std::move(ctx)); });
create_index(std::move(index_name), std::move(keys), options, [barrier](auto ctx) { barrier->set_value(std::move(ctx)); });
return future;
}

Expand Down
37 changes: 24 additions & 13 deletions core/operations/management/query_index_create.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

#include "query_index_create.hxx"

#include "core/utils/join_strings.hxx"
#include "core/utils/json.hxx"
#include "core/utils/keyspace.hxx"
#include "error_utils.hxx"
Expand Down Expand Up @@ -49,19 +48,31 @@ query_index_create_request::encode_to(encoded_request_type& encoded, http_contex
if (with) {
with_clause = fmt::format("WITH {}", utils::json::generate(with));
}
std::string encoded_keys{};
for (std::size_t i = 0; i < keys.size(); i++) {
if (i != 0) {
encoded_keys += ", ";
}
auto key = keys.at(i);

// Add backticks around the key unless they are already present
if (key.at(0) == '`' && key.at(key.size() - 1) == '`') {
encoded_keys += key;
} else {
encoded_keys += fmt::format("`{}`", key);
}
}
std::string keyspace = utils::build_keyspace(*this);
tao::json::value body{ { "statement",
is_primary ? fmt::format(R"(CREATE PRIMARY INDEX {} ON {} USING GSI {})",
index_name.empty() ? "" : fmt::format("`{}`", index_name),
keyspace,
with_clause)
: fmt::format(R"(CREATE INDEX `{}` ON {}({}) {} USING GSI {})",
index_name,
keyspace,
utils::join_strings(fields, ", "),
where_clause,
with_clause) },
{ "client_context_id", encoded.client_context_id } };
tao::json::value body{
{ "statement",
is_primary ? fmt::format(R"(CREATE PRIMARY INDEX {} ON {} USING GSI {})",
index_name.empty() ? "" : fmt::format("`{}`", index_name),
keyspace,
with_clause)
: fmt::format(
R"(CREATE INDEX `{}` ON {}({}) {} USING GSI {})", index_name, keyspace, encoded_keys, where_clause, with_clause) },
{ "client_context_id", encoded.client_context_id }
};
if (query_ctx.has_value()) {
body["query_context"] = query_ctx.value();
}
Expand Down
2 changes: 1 addition & 1 deletion core/operations/management/query_index_create.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ struct query_index_create_request {
std::string scope_name;
std::string collection_name;
std::string index_name{};
std::vector<std::string> fields;
std::vector<std::string> keys;
query_context query_ctx;
bool is_primary{ false };
bool ignore_if_exists{ false };
Expand Down
91 changes: 80 additions & 11 deletions couchbase/collection_query_index_manager.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ class collection_query_index_manager
{
public:
/**
* Get all indexes within a collection.
*
* Get all indexes within the collection.
*
* @param options optional parameters
* @param handler the handler that implements @ref get_all_query_indexes_handler
Expand All @@ -64,30 +63,50 @@ class collection_query_index_manager
*/
void get_all_indexes(const get_all_query_indexes_options& options, get_all_query_indexes_handler&& handler) const;

/**
* Get all indexes within the collection..
*
* @param options optional parameters
* @return future object that carries result of the operation
*
* @since 1.0.0
* @committed
*/
[[nodiscard]] auto get_all_indexes(const get_all_query_indexes_options& options) const
-> std::future<std::pair<manager_error_context, std::vector<couchbase::management::query_index>>>;

/**
* Create an index on the collection.
*
* @param index_name name of the index
* @param fields the fields to create the index over
* @param keys the keys to create the index over
* @param options optional parameters
* @param handler the handler that implements @ref create_query_index_handler
*
* @since 1.0.0
* @committed
*/
void create_index(std::string index_name,
std::vector<std::string> fields,
std::vector<std::string> keys,
const create_query_index_options& options,
create_query_index_handler&& handler) const;

[[nodiscard]] auto create_index(std::string index_name,
std::vector<std::string> fields,
const create_query_index_options& options) const -> std::future<manager_error_context>;
/**
* Create an index on the collection.
*
* @param index_name name of the index
* @param keys the keys to create the index over
* @param options optional parameters
* @return future object that carries result of the operation
*
* @since 1.0.0
* @committed
*/
[[nodiscard]] auto create_index(std::string index_name, std::vector<std::string> keys, const create_query_index_options& options) const
-> std::future<manager_error_context>;

/**
* Create a primary index on a collection.
* Create a primary index on the collection.
*
* @param options optional parameters
* @param handler the handler that implements @ref create_query_index_handler
Expand All @@ -97,10 +116,19 @@ class collection_query_index_manager
*/
void create_primary_index(const create_primary_query_index_options& options, create_query_index_handler&& handler) const;

/**
* Create a primary index on the collection.
*
* @param options optional parameters
* @return future object that carries result of the operation
*
* @since 1.0.0
* @committed
*/
[[nodiscard]] auto create_primary_index(const create_primary_query_index_options& options) const -> std::future<manager_error_context>;

/**
* Drop primary index on a collection.
* Drop primary index on the collection.
*
* @param options optional parameters
* @param handler the handler that implements @ref drop_query_index_handler
Expand All @@ -110,10 +138,19 @@ class collection_query_index_manager
*/
void drop_primary_index(const drop_primary_query_index_options& options, drop_query_index_handler&& handler) const;

/**
* Drop primary index on the collection.
*
* @param options optional parameters
* @return future object that carries result of the operation
*
* @since 1.0.0
* @committed
*/
[[nodiscard]] auto drop_primary_index(const drop_primary_query_index_options& options) const -> std::future<manager_error_context>;

/**
* Drop index in collection.
* Drop specified query index in the collection.
*
* @param index_name name of the index to drop
* @param options optional parameters
Expand All @@ -124,21 +161,43 @@ class collection_query_index_manager
*/
void drop_index(std::string index_name, const drop_query_index_options& options, drop_query_index_handler&& handler) const;

/**
* Drop specified query index in the collection.
*
* @param index_name name of the index to drop
* @param options optional parameters
* @return future object that carries result of the operation
*
* @since 1.0.0
* @committed
*/
[[nodiscard]] auto drop_index(std::string index_name, const drop_query_index_options& options) const
-> std::future<manager_error_context>;

/**
* Builds all currently deferred indexes in this collection.
*
* By default, this method will build the indexes on the collection.
*
* @param options the custom options
* @param options optional parameters
* @param handler the handler that implements @ref build_deferred_query_indexes_handler
*
* @since 1.0.0
* @committed
*/
void build_deferred_indexes(const build_query_index_options& options, build_deferred_query_indexes_handler&& handler) const;

/**
* Builds all currently deferred indexes in this collection.
*
* By default, this method will build the indexes on the collection.
*
* @param options optional parameters
* @return future object that carries result of the operation
*
* @since 1.0.0
* @committed
*/
[[nodiscard]] auto build_deferred_indexes(const build_query_index_options& options) const -> std::future<manager_error_context>;

/**
Expand All @@ -155,6 +214,16 @@ class collection_query_index_manager
const watch_query_indexes_options& options,
watch_query_indexes_handler&& handler) const;

/**
* Polls the state of a set of indexes, until they all are online.
*
* @param index_names names of the indexes to watch
* @param options optional parameters
* @return future object that carries result of the operation
*
* @since 1.0.0
* @committed
*/
[[nodiscard]] auto watch_indexes(std::vector<std::string> index_names, const watch_query_indexes_options& options) const
-> std::future<manager_error_context>;

Expand Down
14 changes: 6 additions & 8 deletions couchbase/query_index_manager.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class query_index_manager
/**
* Get all indexes within a bucket.
*
*
* @param bucket_name specifies the bucket in which we look for the indexes
* @param options optional parameters
* @param handler the handler that implements @ref get_all_query_indexes_handler
Expand All @@ -66,7 +65,6 @@ class query_index_manager
/**
* Get all indexes within a bucket.
*
*
* @param bucket_name specifies the bucket in which we look for the indexes
* @param options optional parameters
* @return future object that carries result of the operation
Expand All @@ -82,7 +80,7 @@ class query_index_manager
*
* @param bucket_name specifies the bucket in which to create the index
* @param index_name name of the index
* @param fields the fields to create the index over
* @param keys the keys to create the index over
* @param options optional parameters
* @param handler the handler that implements @ref create_query_index_handler
*
Expand All @@ -91,7 +89,7 @@ class query_index_manager
*/
void create_index(std::string bucket_name,
std::string index_name,
std::vector<std::string> fields,
std::vector<std::string> keys,
const create_query_index_options& options,
create_query_index_handler&& handler) const;

Expand All @@ -100,7 +98,7 @@ class query_index_manager
*
* @param bucket_name specifies the bucket in which to create the index
* @param index_name name of the index
* @param fields the fields to create the index over
* @param keys the keys to create the index over
* @param options optional parameters
* @return future object that carries result of the operation
*
Expand All @@ -109,7 +107,7 @@ class query_index_manager
*/
[[nodiscard]] auto create_index(std::string bucket_name,
std::string index_name,
std::vector<std::string> fields,
std::vector<std::string> keys,
const create_query_index_options& options) const -> std::future<manager_error_context>;

/**
Expand Down Expand Up @@ -202,7 +200,7 @@ class query_index_manager
* By default, this method will build the indexes on the bucket.
*
* @param bucket_name name of the bucket
* @param options the custom options
* @param options optional parameters
* @param handler the handler that implements @ref build_deferred_query_indexes_handler
*
* @since 1.0.0
Expand All @@ -218,7 +216,7 @@ class query_index_manager
* By default, this method will build the indexes on the bucket.
*
* @param bucket_name name of the bucket
* @param options the custom options
* @param options optional parameters
* @return future object that carries result of the operation
*
* @since 1.0.0
Expand Down
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ unit_test(options)
unit_test(search)
unit_test(query)
unit_test(diagnostics)
unit_test(management)
target_link_libraries(test_unit_jsonsl jsonsl)

integration_benchmark(get)
Expand Down
Loading