|
@@ -1,5 +1,6 @@
|
|
|
#include "database_grpc_impl.hpp"
|
|
#include "database_grpc_impl.hpp"
|
|
|
#include "database_service.hpp"
|
|
#include "database_service.hpp"
|
|
|
|
|
+#include "json_parse.hpp"
|
|
|
#include "persistence/wal.hpp"
|
|
#include "persistence/wal.hpp"
|
|
|
#include "views/projection.hpp"
|
|
#include "views/projection.hpp"
|
|
|
|
|
|
|
@@ -106,9 +107,7 @@ grpc::Status DatabaseGrpcImpl::Insert(
|
|
|
"cannot write to view '" + request->collection() + "': views are read-only");
|
|
"cannot write to view '" + request->collection() + "': views are read-only");
|
|
|
}
|
|
}
|
|
|
try {
|
|
try {
|
|
|
- nlohmann::json data = nlohmann::json::parse(
|
|
|
|
|
- request->data().begin(), request->data().end()
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ nlohmann::json data = smartbotic::db::parse_to_nlohmann(request->data());
|
|
|
|
|
|
|
|
Document doc;
|
|
Document doc;
|
|
|
doc.id = request->id();
|
|
doc.id = request->id();
|
|
@@ -184,7 +183,7 @@ grpc::Status DatabaseGrpcImpl::Get(
|
|
|
|
|
|
|
|
// Apply view projection on the response data
|
|
// Apply view projection on the response data
|
|
|
if (view) {
|
|
if (view) {
|
|
|
- nlohmann::json docJson = nlohmann::json::parse(protoDoc.data());
|
|
|
|
|
|
|
+ nlohmann::json docJson = smartbotic::db::parse_to_nlohmann(protoDoc.data());
|
|
|
docJson = applyProjection(docJson, view->include, view->exclude);
|
|
docJson = applyProjection(docJson, view->include, view->exclude);
|
|
|
protoDoc.set_data(docJson.dump());
|
|
protoDoc.set_data(docJson.dump());
|
|
|
// Preserve view name as the observed collection
|
|
// Preserve view name as the observed collection
|
|
@@ -219,9 +218,7 @@ grpc::Status DatabaseGrpcImpl::Update(
|
|
|
return grpc::Status::OK;
|
|
return grpc::Status::OK;
|
|
|
}
|
|
}
|
|
|
try {
|
|
try {
|
|
|
- nlohmann::json data = nlohmann::json::parse(
|
|
|
|
|
- request->data().begin(), request->data().end()
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ nlohmann::json data = smartbotic::db::parse_to_nlohmann(request->data());
|
|
|
|
|
|
|
|
Document doc;
|
|
Document doc;
|
|
|
doc.data = data;
|
|
doc.data = data;
|
|
@@ -304,9 +301,7 @@ grpc::Status DatabaseGrpcImpl::PatchDocument(
|
|
|
return grpc::Status::OK;
|
|
return grpc::Status::OK;
|
|
|
}
|
|
}
|
|
|
try {
|
|
try {
|
|
|
- nlohmann::json patch = nlohmann::json::parse(
|
|
|
|
|
- request->patch_json().begin(), request->patch_json().end()
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ nlohmann::json patch = smartbotic::db::parse_to_nlohmann(request->patch_json());
|
|
|
|
|
|
|
|
uint64_t newVersion = store_.patchDocument(
|
|
uint64_t newVersion = store_.patchDocument(
|
|
|
request->collection(),
|
|
request->collection(),
|
|
@@ -359,9 +354,7 @@ grpc::Status DatabaseGrpcImpl::Upsert(
|
|
|
"cannot write to view '" + request->collection() + "': views are read-only");
|
|
"cannot write to view '" + request->collection() + "': views are read-only");
|
|
|
}
|
|
}
|
|
|
try {
|
|
try {
|
|
|
- nlohmann::json data = nlohmann::json::parse(
|
|
|
|
|
- request->data().begin(), request->data().end()
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ nlohmann::json data = smartbotic::db::parse_to_nlohmann(request->data());
|
|
|
|
|
|
|
|
bool existed = store_.exists(request->collection(), request->id());
|
|
bool existed = store_.exists(request->collection(), request->id());
|
|
|
|
|
|
|
@@ -589,9 +582,7 @@ grpc::Status DatabaseGrpcImpl::BatchInsert(
|
|
|
|
|
|
|
|
for (const auto& item : request->items()) {
|
|
for (const auto& item : request->items()) {
|
|
|
try {
|
|
try {
|
|
|
- nlohmann::json data = nlohmann::json::parse(
|
|
|
|
|
- item.data().begin(), item.data().end()
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ nlohmann::json data = smartbotic::db::parse_to_nlohmann(item.data());
|
|
|
|
|
|
|
|
Document doc;
|
|
Document doc;
|
|
|
doc.id = item.id();
|
|
doc.id = item.id();
|
|
@@ -705,7 +696,7 @@ grpc::Status DatabaseGrpcImpl::Find(
|
|
|
encryption_.decryptSensitiveFields(doc);
|
|
encryption_.decryptSensitiveFields(doc);
|
|
|
pb::Document protoDoc = toProto(doc);
|
|
pb::Document protoDoc = toProto(doc);
|
|
|
if (view) {
|
|
if (view) {
|
|
|
- nlohmann::json docJson = nlohmann::json::parse(protoDoc.data());
|
|
|
|
|
|
|
+ nlohmann::json docJson = smartbotic::db::parse_to_nlohmann(protoDoc.data());
|
|
|
docJson = applyProjection(docJson, view->include, view->exclude);
|
|
docJson = applyProjection(docJson, view->include, view->exclude);
|
|
|
protoDoc.set_data(docJson.dump());
|
|
protoDoc.set_data(docJson.dump());
|
|
|
// Preserve view name as the observed collection
|
|
// Preserve view name as the observed collection
|
|
@@ -1285,7 +1276,7 @@ Document DatabaseGrpcImpl::fromProto(const pb::Document& proto) {
|
|
|
Document doc;
|
|
Document doc;
|
|
|
doc.id = proto.id();
|
|
doc.id = proto.id();
|
|
|
doc.collection = proto.collection();
|
|
doc.collection = proto.collection();
|
|
|
- doc.data = nlohmann::json::parse(proto.data());
|
|
|
|
|
|
|
+ doc.data = smartbotic::db::parse_to_nlohmann(proto.data());
|
|
|
doc.version = proto.version();
|
|
doc.version = proto.version();
|
|
|
doc.createdAt = proto.created_at();
|
|
doc.createdAt = proto.created_at();
|
|
|
doc.updatedAt = proto.updated_at();
|
|
doc.updatedAt = proto.updated_at();
|
|
@@ -1341,7 +1332,7 @@ std::vector<Filter> DatabaseGrpcImpl::fromProtoFilters(
|
|
|
filter.field = f.field();
|
|
filter.field = f.field();
|
|
|
filter.op = static_cast<FilterOp>(f.op() - 1); // Adjust for UNSPECIFIED
|
|
filter.op = static_cast<FilterOp>(f.op() - 1); // Adjust for UNSPECIFIED
|
|
|
if (!f.value().empty()) {
|
|
if (!f.value().empty()) {
|
|
|
- filter.value = nlohmann::json::parse(f.value());
|
|
|
|
|
|
|
+ filter.value = smartbotic::db::parse_to_nlohmann(f.value());
|
|
|
}
|
|
}
|
|
|
result.push_back(filter);
|
|
result.push_back(filter);
|
|
|
}
|
|
}
|
|
@@ -1394,7 +1385,7 @@ grpc::Status DatabaseGrpcImpl::CreateView(
|
|
|
f.op = static_cast<FilterOp>(pf.op() - 1); // Adjust for UNSPECIFIED
|
|
f.op = static_cast<FilterOp>(pf.op() - 1); // Adjust for UNSPECIFIED
|
|
|
if (!pf.value().empty()) {
|
|
if (!pf.value().empty()) {
|
|
|
try {
|
|
try {
|
|
|
- f.value = nlohmann::json::parse(pf.value());
|
|
|
|
|
|
|
+ f.value = smartbotic::db::parse_to_nlohmann(pf.value());
|
|
|
} catch (...) {
|
|
} catch (...) {
|
|
|
f.value = pf.value(); // fall back to string if not JSON
|
|
f.value = pf.value(); // fall back to string if not JSON
|
|
|
}
|
|
}
|