mirror of
https://github.com/status-im/realm-js.git
synced 2025-02-17 09:06:26 +00:00
transaction rpc methods, return size when creating results
This commit is contained in:
parent
a0f098bff3
commit
18641994c7
@ -26,6 +26,9 @@
|
|||||||
#include "RJSRealm.hpp"
|
#include "RJSRealm.hpp"
|
||||||
#include "RJSUtil.hpp"
|
#include "RJSUtil.hpp"
|
||||||
|
|
||||||
|
#include "shared_realm.hpp"
|
||||||
|
#include "results.hpp"
|
||||||
|
|
||||||
using RPCObjectID = long;
|
using RPCObjectID = long;
|
||||||
using RPCRequest = std::function<std::string(NSDictionary *dictionary)>;
|
using RPCRequest = std::function<std::string(NSDictionary *dictionary)>;
|
||||||
static std::map<std::string, RPCRequest> s_requests;
|
static std::map<std::string, RPCRequest> s_requests;
|
||||||
@ -48,6 +51,21 @@ static RPCObjectID s_id_counter = 0;
|
|||||||
s_objects[realmId] = RealmConstructor(s_context, NULL, 1, &value, NULL);
|
s_objects[realmId] = RealmConstructor(s_context, NULL, 1, &value, NULL);
|
||||||
return "{\"realmId\":" + std::to_string(realmId) + "}";
|
return "{\"realmId\":" + std::to_string(realmId) + "}";
|
||||||
};
|
};
|
||||||
|
s_requests["/begin_transaction"] = [=](NSDictionary *dict) {
|
||||||
|
RPCObjectID realmId = [dict[@"realmId"] longValue];
|
||||||
|
RJSGetInternal<realm::SharedRealm *>(s_objects[realmId])->get()->begin_transaction();
|
||||||
|
return "{}";
|
||||||
|
};
|
||||||
|
s_requests["/cancel_transaction"] = [=](NSDictionary *dict) {
|
||||||
|
RPCObjectID realmId = [dict[@"realmId"] longValue];
|
||||||
|
RJSGetInternal<realm::SharedRealm *>(s_objects[realmId])->get()->cancel_transaction();
|
||||||
|
return "{}";
|
||||||
|
};
|
||||||
|
s_requests["/commit_transaction"] = [=](NSDictionary *dict) {
|
||||||
|
RPCObjectID realmId = [dict[@"realmId"] longValue];
|
||||||
|
RJSGetInternal<realm::SharedRealm *>(s_objects[realmId])->get()->commit_transaction();
|
||||||
|
return "{}";
|
||||||
|
};
|
||||||
s_requests["/create_object"] = [=](NSDictionary *dict) {
|
s_requests["/create_object"] = [=](NSDictionary *dict) {
|
||||||
RPCObjectID newOid = s_id_counter++;
|
RPCObjectID newOid = s_id_counter++;
|
||||||
RPCObjectID realmId = [dict[@"realmId"] longValue];
|
RPCObjectID realmId = [dict[@"realmId"] longValue];
|
||||||
@ -107,7 +125,8 @@ static RPCObjectID s_id_counter = 0;
|
|||||||
JSValueRef results = RealmObjects(s_context, NULL, s_objects[realmId], argumentCount, arguments, &exception);
|
JSValueRef results = RealmObjects(s_context, NULL, s_objects[realmId], argumentCount, arguments, &exception);
|
||||||
JSValueProtect(s_context, results);
|
JSValueProtect(s_context, results);
|
||||||
s_objects[newOid] = (JSObjectRef)results;
|
s_objects[newOid] = (JSObjectRef)results;
|
||||||
return "{\"resultsId\":" + std::to_string(realmId) + "}";
|
size_t size = RJSGetInternal<realm::Results *>((JSObjectRef)results)->size();
|
||||||
|
return "{\"resultsId\":" + std::to_string(realmId) + ", \"size\":" + std::to_string(size) + "}";
|
||||||
};
|
};
|
||||||
s_requests["/get_results_size"] = [=](NSDictionary *dict) {
|
s_requests["/get_results_size"] = [=](NSDictionary *dict) {
|
||||||
RPCObjectID resultsId = [dict[@"resultsId"] longValue];
|
RPCObjectID resultsId = [dict[@"resultsId"] longValue];
|
||||||
|
@ -604,6 +604,11 @@
|
|||||||
"$(SRCROOT)/examples/ReactExample/node_modules/react-native/React/",
|
"$(SRCROOT)/examples/ReactExample/node_modules/react-native/React/",
|
||||||
);
|
);
|
||||||
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
|
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
|
||||||
|
OTHER_CPLUSPLUSFLAGS = (
|
||||||
|
"$(OTHER_CFLAGS)",
|
||||||
|
"-isystem",
|
||||||
|
core/include,
|
||||||
|
);
|
||||||
OTHER_LDFLAGS = "-ObjC";
|
OTHER_LDFLAGS = "-ObjC";
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SKIP_INSTALL = YES;
|
SKIP_INSTALL = YES;
|
||||||
@ -624,6 +629,11 @@
|
|||||||
"$(SRCROOT)/examples/ReactExample/node_modules/react-native/React/",
|
"$(SRCROOT)/examples/ReactExample/node_modules/react-native/React/",
|
||||||
);
|
);
|
||||||
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
|
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
|
||||||
|
OTHER_CPLUSPLUSFLAGS = (
|
||||||
|
"$(OTHER_CFLAGS)",
|
||||||
|
"-isystem",
|
||||||
|
core/include,
|
||||||
|
);
|
||||||
OTHER_LDFLAGS = "-ObjC";
|
OTHER_LDFLAGS = "-ObjC";
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SKIP_INSTALL = YES;
|
SKIP_INSTALL = YES;
|
||||||
@ -644,6 +654,11 @@
|
|||||||
"$(SRCROOT)/examples/ReactExample/node_modules/react-native/React/",
|
"$(SRCROOT)/examples/ReactExample/node_modules/react-native/React/",
|
||||||
);
|
);
|
||||||
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
|
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
|
||||||
|
OTHER_CPLUSPLUSFLAGS = (
|
||||||
|
"$(OTHER_CFLAGS)",
|
||||||
|
"-isystem",
|
||||||
|
core/include,
|
||||||
|
);
|
||||||
OTHER_LDFLAGS = "-ObjC";
|
OTHER_LDFLAGS = "-ObjC";
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SKIP_INSTALL = YES;
|
SKIP_INSTALL = YES;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user