Exposing a Realms groups compute_aggregated_byte_size via computeSize

This commit is contained in:
Kræn Hansen 2018-06-20 16:00:12 +02:00
parent 8a7d7a30a5
commit 10c127542b

View File

@ -237,6 +237,7 @@ public:
static void delete_model(ContextType, ObjectType, Arguments, ReturnValue &);
static void object_for_object_id(ContextType, ObjectType, Arguments, ReturnValue&);
static void privileges(ContextType, ObjectType, Arguments, ReturnValue&);
static void compute_size(ContextType, ObjectType, Arguments, ReturnValue&);
// properties
static void get_empty(ContextType, ObjectType, ReturnValue &);
@ -295,6 +296,7 @@ public:
{"writeCopyTo", wrap<writeCopyTo>},
{"deleteModel", wrap<delete_model>},
{"privileges", wrap<privileges>},
{"computeSize", wrap<compute_size>},
{"_objectForObjectId", wrap<object_for_object_id>},
#if REALM_ENABLE_SYNC
{"_waitForDownload", wrap<wait_for_download_completion>},
@ -1176,5 +1178,14 @@ void RealmClass<T>::privileges(ContextType ctx, ObjectType this_object, Argument
return_value.set(object);
}
template<typename T>
void RealmClass<T>::compute_size(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue &return_value) {
args.validate_maximum(0);
SharedRealm realm = *get_internal<T, RealmClass<T>>(this_object);
auto size = realm->read_group().compute_aggregated_byte_size();
return_value.set(Value::from_number(ctx, size));
}
} // js
} // realm