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
8 changes: 6 additions & 2 deletions core/operations/management/collection_create.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ collection_create_request::encode_to(encoded_request_type& encoded, http_context
encoded.path = fmt::format("/pools/default/buckets/{}/scopes/{}/collections", bucket_name, scope_name);
encoded.headers["content-type"] = "application/x-www-form-urlencoded";
encoded.body = fmt::format("name={}", utils::string_codec::form_encode(collection_name));
if (max_expiry > 0) {
encoded.body.append(fmt::format("&maxTTL={}", max_expiry));
if (max_expiry >= -1) {
if (max_expiry != 0) {
encoded.body.append(fmt::format("&maxTTL={}", max_expiry));
}
} else {
return couchbase::errc::common::invalid_argument;
}
if (history.has_value()) {
encoded.body.append(fmt::format("&history={}", history.value()));
Expand Down
2 changes: 1 addition & 1 deletion core/operations/management/collection_create.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct collection_create_request {
std::string bucket_name;
std::string scope_name;
std::string collection_name;
std::uint32_t max_expiry{ 0 };
std::int32_t max_expiry{ 0 };
std::optional<bool> history{};

std::optional<std::string> client_context_id{};
Expand Down
6 changes: 5 additions & 1 deletion core/operations/management/collection_update.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ collection_update_request::encode_to(encoded_request_type& encoded, http_context
encoded.headers["content-type"] = "application/x-www-form-urlencoded";
std::map<std::string, std::string> values{};
if (max_expiry.has_value()) {
values["maxTTL"] = std::to_string(max_expiry.value());
if (max_expiry.value() >= -1) {
values["maxTTL"] = std::to_string(max_expiry.value());
} else {
return errc::common::invalid_argument;
}
}
if (history.has_value()) {
values["history"] = history.value() ? "true" : "false";
Expand Down
2 changes: 1 addition & 1 deletion core/operations/management/collection_update.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct collection_update_request {
std::string bucket_name;
std::string scope_name;
std::string collection_name;
std::optional<std::uint32_t> max_expiry{};
std::optional<std::int32_t> max_expiry{};
std::optional<bool> history{};

std::optional<std::string> client_context_id{};
Expand Down
2 changes: 1 addition & 1 deletion core/topology/collections_manifest.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct collections_manifest {
struct collection {
std::uint64_t uid;
std::string name;
std::uint32_t max_expiry{ 0 };
std::int32_t max_expiry{ 0 };
std::optional<bool> history{};
};

Expand Down
2 changes: 1 addition & 1 deletion core/topology/collections_manifest_json.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct traits<couchbase::core::topology::collections_manifest> {
collection.uid = std::stoull(c.at("uid").get_string(), nullptr, 16);
collection.name = c.at("name").get_string();
if (const auto* max_ttl = c.find("maxTTL"); max_ttl != nullptr) {
collection.max_expiry = max_ttl->template as<std::uint32_t>();
collection.max_expiry = max_ttl->template as<std::int32_t>();
}
if (const auto* history = c.find("history"); history != nullptr) {
collection.history = history->template as<std::optional<bool>>();
Expand Down
30 changes: 29 additions & 1 deletion couchbase/create_collection_options.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,52 @@
#include <couchbase/common_options.hxx>
#include <couchbase/manager_error_context.hxx>

#include <cstdint>
#include <functional>
#include <optional>

namespace couchbase
{
struct create_collection_options : public common_options<create_collection_options> {
public:
/**
* Immutable value object representing consistent options.
*
* @since 1.0.0
* @internal
*/
struct built : public common_options<create_collection_options>::built {
};

/**
* Validates the options and returns them as an immutable value.
*
* @return consistent options as an immutable value
*
* @exception std::system_error with code errc::common::invalid_argument if the options are not valid
*
* @since 1.0.0
* @internal
*/
[[nodiscard]] auto build() const -> built
{
return { build_common_options() };
}
};

/**
* The settings to use when creating the collection
*/
struct create_collection_settings {
std::uint32_t max_expiry{ 0 };
/**
* The maximum expiry, in seconds, for documents in this collection. Values greater than or equal to -1 are valid.
* Value of 0 sets max_expiry to the bucket-level setting and value of -1 to set it as no-expiry.
*/
std::int32_t max_expiry{ 0 };

/**
* Whether history retention should be enabled. If unset, the bucket-level setting is used.
*/
std::optional<bool> history{};
};

Expand Down
2 changes: 1 addition & 1 deletion couchbase/management/collection_spec.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace couchbase::management::bucket
struct collection_spec {
std::string name;
std::string scope_name;
std::uint32_t max_expiry{};
std::int32_t max_expiry{};
std::optional<bool> history{};
};

Expand Down
35 changes: 32 additions & 3 deletions couchbase/update_collection_options.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,55 @@

#pragma once

#include <functional>
#include <couchbase/common_options.hxx>
#include <couchbase/manager_error_context.hxx>

#include <cstdint>
#include <memory>
#include <optional>
#include <string>

namespace couchbase
{
struct update_collection_options : public common_options<update_collection_options> {
public:
/**
* Immutable value object representing consistent options.
*
* @since 1.0.0
* @internal
*/
struct built : public common_options<update_collection_options>::built {
};

/**
* Validates the options and returns them as an immutable value.
*
* @return consistent options as an immutable value
*
* @exception std::system_error with code errc::common::invalid_argument if the options are not valid
*
* @since 1.0.0
* @internal
*/
[[nodiscard]] auto build() const -> built
{
return { build_common_options() };
}
};

/**
* The settings that should be updated for the collection
*/
struct update_collection_settings {
std::optional<std::uint32_t> max_expiry{};
/**
* The maximum expiry, in seconds, for documents in this collection. Values greater than or equal to -1 are valid.
* Value of 0 sets max_expiry to the bucket-level setting and value of -1 to set it as no-expiry.
*/
std::optional<std::int32_t> max_expiry{};

/**
* Whether history retention should be enabled.
*/
std::optional<bool> history{};
};

Expand Down
Loading