Support delete and deleteAll from RPC

This commit is contained in:
Scott Kyle 2015-10-08 01:53:22 -07:00
parent 31fc14d602
commit ebb400ed41
4 changed files with 45 additions and 5 deletions

View File

@ -73,7 +73,34 @@ static JSGlobalContextRef s_context;
inContext:[JSContext contextWithJSGlobalContextRef:s_context]] JSValueRef]; inContext:[JSContext contextWithJSGlobalContextRef:s_context]] JSValueRef];
JSValueRef exception = NULL; JSValueRef exception = NULL;
RPCObjectID oid = [self storeObject:(JSObjectRef)RealmCreateObject(s_context, NULL, s_objects[realmId], 1, &value, &exception)]; RPCObjectID oid = [self storeObject:(JSObjectRef)RealmCreateObject(s_context, NULL, s_objects[realmId], 1, &value, &exception)];
return @{@"result": @{@"type": @"PropTypesOBJECT", @"id": @(oid)}};
if (exception) {
return @{@"error": @(RJSStringForValue(s_context, exception).c_str())};
}
return @{@"result": @{@"type": @(RJSTypeGet(realm::PropertyTypeObject).c_str()), @"id": @(oid)}};
};
s_requests["/delete_object"] = [=](NSDictionary *dict) {
RPCObjectID realmId = [dict[@"realmId"] longValue];
JSValueRef jsObject = [self valueFromDictionary:dict[@"object"]];
JSValueRef exception = NULL;
RealmDelete(s_context, NULL, s_objects[realmId], 1, &jsObject, &exception);
if (exception) {
return @{@"error": @(RJSStringForValue(s_context, exception).c_str())};
}
return @{};
};
s_requests["/delete_all"] = [=](NSDictionary *dict) {
RPCObjectID realmId = [dict[@"realmId"] longValue];
JSValueRef exception = NULL;
RealmDeleteAll(s_context, NULL, s_objects[realmId], 0, NULL, &exception);
if (exception) {
return @{@"error": @(RJSStringForValue(s_context, exception).c_str())};
}
return @{};
}; };
s_requests["/dispose_realm"] = [=](NSDictionary *dict) { s_requests["/dispose_realm"] = [=](NSDictionary *dict) {
RPCObjectID realmId = [dict[@"realmId"] longValue]; RPCObjectID realmId = [dict[@"realmId"] longValue];

View File

@ -46,11 +46,11 @@ class Realm {
} }
delete(object) { delete(object) {
// TODO rpc.deleteObject(this[realmKey], object);
} }
deleteAll() { deleteAll() {
// TODO rpc.deleteAll(this[realmKey]);
} }
objects(type, predicate) { objects(type, predicate) {

View File

@ -21,6 +21,8 @@ exports.registerTypeConverter = registerTypeConverter;
exports.createRealm = createRealm; exports.createRealm = createRealm;
exports.createObject = createObject; exports.createObject = createObject;
exports.deleteObject = deleteObject;
exports.deleteAllObjects = deleteAllObjects;
exports.getObjects = getObjects; exports.getObjects = getObjects;
exports.getObjectProperty = getObjectProperty; exports.getObjectProperty = getObjectProperty;
@ -50,6 +52,15 @@ function createObject(realmId, type, values) {
return sendRequest('create_object', {realmId, type, values}); return sendRequest('create_object', {realmId, type, values});
} }
function deleteObject(realmId, object) {
object = serialize(realmId, object);
sendRequest('delete_object', {realmId, object});
}
function deleteAllObjects(realmId) {
sendRequest('delete_all', {realmId});
}
function getObjects(realmId, type, predicate) { function getObjects(realmId, type, predicate) {
return sendRequest('get_objects', {realmId, type, predicate}); return sendRequest('get_objects', {realmId, type, predicate});
} }

View File

@ -27,4 +27,6 @@ void RJSSetDefaultPath(std::string path);
JSObjectRef RealmConstructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* jsException); JSObjectRef RealmConstructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* jsException);
JSValueRef RealmCreateObject(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* jsException); JSValueRef RealmCreateObject(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* jsException);
JSValueRef RealmDelete(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* jsException);
JSValueRef RealmDeleteAll(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* jsException);
JSValueRef RealmObjects(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* jsException); JSValueRef RealmObjects(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* jsException);