Support delete and deleteAll from RPC
This commit is contained in:
parent
31fc14d602
commit
ebb400ed41
|
@ -73,7 +73,34 @@ static JSGlobalContextRef s_context;
|
|||
inContext:[JSContext contextWithJSGlobalContextRef:s_context]] JSValueRef];
|
||||
JSValueRef exception = NULL;
|
||||
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) {
|
||||
RPCObjectID realmId = [dict[@"realmId"] longValue];
|
||||
|
|
|
@ -44,13 +44,13 @@ class Realm {
|
|||
|
||||
return objects.create(realmId, info);
|
||||
}
|
||||
|
||||
|
||||
delete(object) {
|
||||
// TODO
|
||||
rpc.deleteObject(this[realmKey], object);
|
||||
}
|
||||
|
||||
|
||||
deleteAll() {
|
||||
// TODO
|
||||
rpc.deleteAll(this[realmKey]);
|
||||
}
|
||||
|
||||
objects(type, predicate) {
|
||||
|
|
11
lib/rpc.js
11
lib/rpc.js
|
@ -21,6 +21,8 @@ exports.registerTypeConverter = registerTypeConverter;
|
|||
|
||||
exports.createRealm = createRealm;
|
||||
exports.createObject = createObject;
|
||||
exports.deleteObject = deleteObject;
|
||||
exports.deleteAllObjects = deleteAllObjects;
|
||||
exports.getObjects = getObjects;
|
||||
|
||||
exports.getObjectProperty = getObjectProperty;
|
||||
|
@ -50,6 +52,15 @@ function createObject(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) {
|
||||
return sendRequest('get_objects', {realmId, type, predicate});
|
||||
}
|
||||
|
|
|
@ -27,4 +27,6 @@ void RJSSetDefaultPath(std::string path);
|
|||
|
||||
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 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);
|
Loading…
Reference in New Issue