|
@@ -44,7 +44,26 @@ uint32_t computeBackoffMs(uint32_t baseMs, uint32_t attempt, uint32_t capMs, dou
|
|
|
|
|
|
|
|
class Client::Impl {
|
|
class Client::Impl {
|
|
|
public:
|
|
public:
|
|
|
- explicit Impl(Config config) : config_(std::move(config)) {}
|
|
|
|
|
|
|
+ explicit Impl(Config config) : config_(std::move(config)) {
|
|
|
|
|
+ if (config_.project.empty()) config_.project = "default";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // v2.3 — qualify a collection name with Config::project unless the
|
|
|
|
|
+ // caller already supplied a "<project>:<collection>" qualified form.
|
|
|
|
|
+ // The qualified form always wins. Server-side parseProjectCollection
|
|
|
|
|
+ // is strict on edge cases (leading colon, double colon, etc.) so
|
|
|
|
|
+ // we just delegate the validation to the server.
|
|
|
|
|
+ std::string qualify(std::string_view collection) const {
|
|
|
|
|
+ if (collection.find(':') != std::string_view::npos) {
|
|
|
|
|
+ return std::string(collection);
|
|
|
|
|
+ }
|
|
|
|
|
+ std::string out;
|
|
|
|
|
+ out.reserve(config_.project.size() + 1 + collection.size());
|
|
|
|
|
+ out.append(config_.project);
|
|
|
|
|
+ out.push_back(':');
|
|
|
|
|
+ out.append(collection.data(), collection.size());
|
|
|
|
|
+ return out;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
~Impl() {
|
|
~Impl() {
|
|
|
disconnect();
|
|
disconnect();
|
|
@@ -101,7 +120,7 @@ public:
|
|
|
const std::string& id, uint32_t ttlSeconds,
|
|
const std::string& id, uint32_t ttlSeconds,
|
|
|
const std::string& actor) {
|
|
const std::string& actor) {
|
|
|
smartbotic::databasepb::InsertRequest request;
|
|
smartbotic::databasepb::InsertRequest request;
|
|
|
- request.set_collection(collection);
|
|
|
|
|
|
|
+ request.set_collection(qualify(collection));
|
|
|
request.set_data(data.dump());
|
|
request.set_data(data.dump());
|
|
|
if (!id.empty()) {
|
|
if (!id.empty()) {
|
|
|
request.set_id(id);
|
|
request.set_id(id);
|
|
@@ -143,7 +162,7 @@ public:
|
|
|
|
|
|
|
|
std::optional<nlohmann::json> get(const std::string& collection, const std::string& id) {
|
|
std::optional<nlohmann::json> get(const std::string& collection, const std::string& id) {
|
|
|
smartbotic::databasepb::GetRequest request;
|
|
smartbotic::databasepb::GetRequest request;
|
|
|
- request.set_collection(collection);
|
|
|
|
|
|
|
+ request.set_collection(qualify(collection));
|
|
|
request.set_id(id);
|
|
request.set_id(id);
|
|
|
|
|
|
|
|
smartbotic::databasepb::GetResponse response;
|
|
smartbotic::databasepb::GetResponse response;
|
|
@@ -215,7 +234,7 @@ public:
|
|
|
const nlohmann::json& data, uint64_t expectedVersion,
|
|
const nlohmann::json& data, uint64_t expectedVersion,
|
|
|
const std::string& actor) {
|
|
const std::string& actor) {
|
|
|
smartbotic::databasepb::UpdateRequest request;
|
|
smartbotic::databasepb::UpdateRequest request;
|
|
|
- request.set_collection(collection);
|
|
|
|
|
|
|
+ request.set_collection(qualify(collection));
|
|
|
request.set_id(id);
|
|
request.set_id(id);
|
|
|
request.set_data(data.dump());
|
|
request.set_data(data.dump());
|
|
|
request.set_expected_version(expectedVersion);
|
|
request.set_expected_version(expectedVersion);
|
|
@@ -254,7 +273,7 @@ public:
|
|
|
uint64_t patch(const std::string& collection, const std::string& id,
|
|
uint64_t patch(const std::string& collection, const std::string& id,
|
|
|
const nlohmann::json& fields, const std::string& actor) {
|
|
const nlohmann::json& fields, const std::string& actor) {
|
|
|
smartbotic::databasepb::PatchDocumentRequest request;
|
|
smartbotic::databasepb::PatchDocumentRequest request;
|
|
|
- request.set_collection(collection);
|
|
|
|
|
|
|
+ request.set_collection(qualify(collection));
|
|
|
request.set_id(id);
|
|
request.set_id(id);
|
|
|
request.set_patch_json(fields.dump());
|
|
request.set_patch_json(fields.dump());
|
|
|
if (!actor.empty()) {
|
|
if (!actor.empty()) {
|
|
@@ -298,7 +317,7 @@ public:
|
|
|
const std::string& id, uint32_t ttlSeconds,
|
|
const std::string& id, uint32_t ttlSeconds,
|
|
|
const std::string& actor) {
|
|
const std::string& actor) {
|
|
|
smartbotic::databasepb::UpsertRequest request;
|
|
smartbotic::databasepb::UpsertRequest request;
|
|
|
- request.set_collection(collection);
|
|
|
|
|
|
|
+ request.set_collection(qualify(collection));
|
|
|
request.set_data(data.dump());
|
|
request.set_data(data.dump());
|
|
|
if (!id.empty()) {
|
|
if (!id.empty()) {
|
|
|
request.set_id(id);
|
|
request.set_id(id);
|
|
@@ -340,7 +359,7 @@ public:
|
|
|
|
|
|
|
|
bool remove(const std::string& collection, const std::string& id) {
|
|
bool remove(const std::string& collection, const std::string& id) {
|
|
|
smartbotic::databasepb::DeleteRequest request;
|
|
smartbotic::databasepb::DeleteRequest request;
|
|
|
- request.set_collection(collection);
|
|
|
|
|
|
|
+ request.set_collection(qualify(collection));
|
|
|
request.set_id(id);
|
|
request.set_id(id);
|
|
|
|
|
|
|
|
smartbotic::databasepb::DeleteResponse response;
|
|
smartbotic::databasepb::DeleteResponse response;
|
|
@@ -373,7 +392,7 @@ public:
|
|
|
|
|
|
|
|
bool exists(const std::string& collection, const std::string& id) {
|
|
bool exists(const std::string& collection, const std::string& id) {
|
|
|
smartbotic::databasepb::ExistsRequest request;
|
|
smartbotic::databasepb::ExistsRequest request;
|
|
|
- request.set_collection(collection);
|
|
|
|
|
|
|
+ request.set_collection(qualify(collection));
|
|
|
request.set_id(id);
|
|
request.set_id(id);
|
|
|
|
|
|
|
|
smartbotic::databasepb::ExistsResponse response;
|
|
smartbotic::databasepb::ExistsResponse response;
|
|
@@ -394,7 +413,7 @@ public:
|
|
|
std::vector<nlohmann::json> find(const std::string& collection,
|
|
std::vector<nlohmann::json> find(const std::string& collection,
|
|
|
const Client::QueryOptions& options) {
|
|
const Client::QueryOptions& options) {
|
|
|
smartbotic::databasepb::FindRequest request;
|
|
smartbotic::databasepb::FindRequest request;
|
|
|
- request.set_collection(collection);
|
|
|
|
|
|
|
+ request.set_collection(qualify(collection));
|
|
|
|
|
|
|
|
// Set filters
|
|
// Set filters
|
|
|
for (const auto& filter : options.filters) {
|
|
for (const auto& filter : options.filters) {
|
|
@@ -444,7 +463,7 @@ public:
|
|
|
Client::FindResult findWithMetrics(const std::string& collection,
|
|
Client::FindResult findWithMetrics(const std::string& collection,
|
|
|
const Client::QueryOptions& options) {
|
|
const Client::QueryOptions& options) {
|
|
|
smartbotic::databasepb::FindRequest request;
|
|
smartbotic::databasepb::FindRequest request;
|
|
|
- request.set_collection(collection);
|
|
|
|
|
|
|
+ request.set_collection(qualify(collection));
|
|
|
|
|
|
|
|
// Set filters
|
|
// Set filters
|
|
|
for (const auto& filter : options.filters) {
|
|
for (const auto& filter : options.filters) {
|
|
@@ -502,7 +521,7 @@ public:
|
|
|
uint64_t count(const std::string& collection,
|
|
uint64_t count(const std::string& collection,
|
|
|
const std::vector<Client::Filter>& filters) {
|
|
const std::vector<Client::Filter>& filters) {
|
|
|
smartbotic::databasepb::CountRequest request;
|
|
smartbotic::databasepb::CountRequest request;
|
|
|
- request.set_collection(collection);
|
|
|
|
|
|
|
+ request.set_collection(qualify(collection));
|
|
|
|
|
|
|
|
for (const auto& filter : filters) {
|
|
for (const auto& filter : filters) {
|
|
|
auto* pb = request.add_filters();
|
|
auto* pb = request.add_filters();
|
|
@@ -528,7 +547,7 @@ public:
|
|
|
|
|
|
|
|
bool setAdd(const std::string& collection, const std::string& setId, const std::string& member) {
|
|
bool setAdd(const std::string& collection, const std::string& setId, const std::string& member) {
|
|
|
smartbotic::databasepb::SetAddRequest request;
|
|
smartbotic::databasepb::SetAddRequest request;
|
|
|
- request.set_collection(collection);
|
|
|
|
|
|
|
+ request.set_collection(qualify(collection));
|
|
|
request.set_set_id(setId);
|
|
request.set_set_id(setId);
|
|
|
request.set_member(member);
|
|
request.set_member(member);
|
|
|
|
|
|
|
@@ -547,7 +566,7 @@ public:
|
|
|
|
|
|
|
|
bool setRemove(const std::string& collection, const std::string& setId, const std::string& member) {
|
|
bool setRemove(const std::string& collection, const std::string& setId, const std::string& member) {
|
|
|
smartbotic::databasepb::SetRemoveRequest request;
|
|
smartbotic::databasepb::SetRemoveRequest request;
|
|
|
- request.set_collection(collection);
|
|
|
|
|
|
|
+ request.set_collection(qualify(collection));
|
|
|
request.set_set_id(setId);
|
|
request.set_set_id(setId);
|
|
|
request.set_member(member);
|
|
request.set_member(member);
|
|
|
|
|
|
|
@@ -566,7 +585,7 @@ public:
|
|
|
|
|
|
|
|
std::vector<std::string> setMembers(const std::string& collection, const std::string& setId) {
|
|
std::vector<std::string> setMembers(const std::string& collection, const std::string& setId) {
|
|
|
smartbotic::databasepb::SetMembersRequest request;
|
|
smartbotic::databasepb::SetMembersRequest request;
|
|
|
- request.set_collection(collection);
|
|
|
|
|
|
|
+ request.set_collection(qualify(collection));
|
|
|
request.set_set_id(setId);
|
|
request.set_set_id(setId);
|
|
|
|
|
|
|
|
smartbotic::databasepb::SetMembersResponse response;
|
|
smartbotic::databasepb::SetMembersResponse response;
|
|
@@ -584,7 +603,7 @@ public:
|
|
|
|
|
|
|
|
bool setIsMember(const std::string& collection, const std::string& setId, const std::string& member) {
|
|
bool setIsMember(const std::string& collection, const std::string& setId, const std::string& member) {
|
|
|
smartbotic::databasepb::SetIsMemberRequest request;
|
|
smartbotic::databasepb::SetIsMemberRequest request;
|
|
|
- request.set_collection(collection);
|
|
|
|
|
|
|
+ request.set_collection(qualify(collection));
|
|
|
request.set_set_id(setId);
|
|
request.set_set_id(setId);
|
|
|
request.set_member(member);
|
|
request.set_member(member);
|
|
|
|
|
|
|
@@ -607,7 +626,7 @@ public:
|
|
|
const std::string& collection, const std::vector<float>& queryVector,
|
|
const std::string& collection, const std::vector<float>& queryVector,
|
|
|
uint32_t topK, float minScore) {
|
|
uint32_t topK, float minScore) {
|
|
|
smartbotic::databasepb::SimilaritySearchRequest request;
|
|
smartbotic::databasepb::SimilaritySearchRequest request;
|
|
|
- request.set_collection(collection);
|
|
|
|
|
|
|
+ request.set_collection(qualify(collection));
|
|
|
for (float v : queryVector) {
|
|
for (float v : queryVector) {
|
|
|
request.add_query_vector(v);
|
|
request.add_query_vector(v);
|
|
|
}
|
|
}
|
|
@@ -797,7 +816,7 @@ public:
|
|
|
|
|
|
|
|
bool configureCollection(const std::string& collection, const Client::CollectionConfig& cfg) {
|
|
bool configureCollection(const std::string& collection, const Client::CollectionConfig& cfg) {
|
|
|
smartbotic::databasepb::ConfigureCollectionRequest request;
|
|
smartbotic::databasepb::ConfigureCollectionRequest request;
|
|
|
- request.set_collection(collection);
|
|
|
|
|
|
|
+ request.set_collection(qualify(collection));
|
|
|
request.mutable_config()->set_timestamp_precision(cfg.timestampPrecision);
|
|
request.mutable_config()->set_timestamp_precision(cfg.timestampPrecision);
|
|
|
|
|
|
|
|
smartbotic::databasepb::ConfigureCollectionResponse response;
|
|
smartbotic::databasepb::ConfigureCollectionResponse response;
|
|
@@ -818,7 +837,7 @@ public:
|
|
|
|
|
|
|
|
Client::CollectionConfig getCollectionConfig(const std::string& collection) {
|
|
Client::CollectionConfig getCollectionConfig(const std::string& collection) {
|
|
|
smartbotic::databasepb::GetCollectionConfigRequest request;
|
|
smartbotic::databasepb::GetCollectionConfigRequest request;
|
|
|
- request.set_collection(collection);
|
|
|
|
|
|
|
+ request.set_collection(qualify(collection));
|
|
|
|
|
|
|
|
smartbotic::databasepb::GetCollectionConfigResponse response;
|
|
smartbotic::databasepb::GetCollectionConfigResponse response;
|
|
|
grpc::ClientContext context;
|
|
grpc::ClientContext context;
|
|
@@ -837,7 +856,7 @@ public:
|
|
|
|
|
|
|
|
bool hasCollectionConfig(const std::string& collection) {
|
|
bool hasCollectionConfig(const std::string& collection) {
|
|
|
smartbotic::databasepb::GetCollectionConfigRequest request;
|
|
smartbotic::databasepb::GetCollectionConfigRequest request;
|
|
|
- request.set_collection(collection);
|
|
|
|
|
|
|
+ request.set_collection(qualify(collection));
|
|
|
|
|
|
|
|
smartbotic::databasepb::GetCollectionConfigResponse response;
|
|
smartbotic::databasepb::GetCollectionConfigResponse response;
|
|
|
grpc::ClientContext context;
|
|
grpc::ClientContext context;
|
|
@@ -854,7 +873,7 @@ public:
|
|
|
const std::string& toPrecision
|
|
const std::string& toPrecision
|
|
|
) {
|
|
) {
|
|
|
smartbotic::databasepb::MigrateCollectionTimestampsRequest request;
|
|
smartbotic::databasepb::MigrateCollectionTimestampsRequest request;
|
|
|
- request.set_collection(collection);
|
|
|
|
|
|
|
+ request.set_collection(qualify(collection));
|
|
|
request.set_from_precision(fromPrecision);
|
|
request.set_from_precision(fromPrecision);
|
|
|
request.set_to_precision(toPrecision);
|
|
request.set_to_precision(toPrecision);
|
|
|
|
|
|
|
@@ -888,7 +907,7 @@ public:
|
|
|
const std::optional<Client::Sort>& defaultSort) {
|
|
const std::optional<Client::Sort>& defaultSort) {
|
|
|
smartbotic::databasepb::CreateViewRequest request;
|
|
smartbotic::databasepb::CreateViewRequest request;
|
|
|
request.set_name(name);
|
|
request.set_name(name);
|
|
|
- request.set_collection(collection);
|
|
|
|
|
|
|
+ request.set_collection(qualify(collection));
|
|
|
for (const auto& p : include) request.add_include(p);
|
|
for (const auto& p : include) request.add_include(p);
|
|
|
for (const auto& p : exclude) request.add_exclude(p);
|
|
for (const auto& p : exclude) request.add_exclude(p);
|
|
|
|
|
|
|
@@ -1095,7 +1114,7 @@ public:
|
|
|
Client::VersionHistoryResult getVersionHistory(const std::string& collection,
|
|
Client::VersionHistoryResult getVersionHistory(const std::string& collection,
|
|
|
const std::string& id, uint32_t limit, uint32_t offset) {
|
|
const std::string& id, uint32_t limit, uint32_t offset) {
|
|
|
smartbotic::databasepb::GetVersionHistoryRequest request;
|
|
smartbotic::databasepb::GetVersionHistoryRequest request;
|
|
|
- request.set_collection(collection);
|
|
|
|
|
|
|
+ request.set_collection(qualify(collection));
|
|
|
request.set_id(id);
|
|
request.set_id(id);
|
|
|
if (limit > 0) request.set_limit(limit);
|
|
if (limit > 0) request.set_limit(limit);
|
|
|
if (offset > 0) request.set_offset(offset);
|
|
if (offset > 0) request.set_offset(offset);
|
|
@@ -1133,7 +1152,7 @@ public:
|
|
|
std::optional<Client::VersionEntry> getDocumentVersion(const std::string& collection,
|
|
std::optional<Client::VersionEntry> getDocumentVersion(const std::string& collection,
|
|
|
const std::string& id, uint64_t version) {
|
|
const std::string& id, uint64_t version) {
|
|
|
smartbotic::databasepb::GetDocumentVersionRequest request;
|
|
smartbotic::databasepb::GetDocumentVersionRequest request;
|
|
|
- request.set_collection(collection);
|
|
|
|
|
|
|
+ request.set_collection(qualify(collection));
|
|
|
request.set_id(id);
|
|
request.set_id(id);
|
|
|
request.set_version(version);
|
|
request.set_version(version);
|
|
|
|
|
|
|
@@ -1164,7 +1183,7 @@ public:
|
|
|
uint64_t restoreVersion(const std::string& collection, const std::string& id,
|
|
uint64_t restoreVersion(const std::string& collection, const std::string& id,
|
|
|
uint64_t version, const std::string& actor) {
|
|
uint64_t version, const std::string& actor) {
|
|
|
smartbotic::databasepb::RestoreVersionRequest request;
|
|
smartbotic::databasepb::RestoreVersionRequest request;
|
|
|
- request.set_collection(collection);
|
|
|
|
|
|
|
+ request.set_collection(qualify(collection));
|
|
|
request.set_id(id);
|
|
request.set_id(id);
|
|
|
request.set_version(version);
|
|
request.set_version(version);
|
|
|
if (!actor.empty()) request.set_actor(actor);
|
|
if (!actor.empty()) request.set_actor(actor);
|
|
@@ -1190,7 +1209,7 @@ public:
|
|
|
std::pair<uint64_t, uint64_t> restoreToDate(const std::string& collection,
|
|
std::pair<uint64_t, uint64_t> restoreToDate(const std::string& collection,
|
|
|
const std::string& id, uint64_t timestamp, const std::string& actor) {
|
|
const std::string& id, uint64_t timestamp, const std::string& actor) {
|
|
|
smartbotic::databasepb::RestoreToDateRequest request;
|
|
smartbotic::databasepb::RestoreToDateRequest request;
|
|
|
- request.set_collection(collection);
|
|
|
|
|
|
|
+ request.set_collection(qualify(collection));
|
|
|
request.set_id(id);
|
|
request.set_id(id);
|
|
|
request.set_timestamp(timestamp);
|
|
request.set_timestamp(timestamp);
|
|
|
if (!actor.empty()) request.set_actor(actor);
|
|
if (!actor.empty()) request.set_actor(actor);
|