diff --git a/src/js_object_accessor.hpp b/src/js_object_accessor.hpp index bce1089d..d9ec7f1b 100644 --- a/src/js_object_accessor.hpp +++ b/src/js_object_accessor.hpp @@ -112,7 +112,7 @@ struct NativeAccessor { } } - auto object_schema = realm->config().schema->find(type); + auto object_schema = realm->schema().find(type); if (Value::is_array(ctx, object)) { object = Schema::dict_for_property_array(ctx, *object_schema, object); } diff --git a/src/js_realm.hpp b/src/js_realm.hpp index ed0ce5e0..06821ac3 100644 --- a/src/js_realm.hpp +++ b/src/js_realm.hpp @@ -230,10 +230,10 @@ public: object_type = Value::validated_to_string(ctx, value, "objectType"); } - auto &schema = realm->config().schema; - auto object_schema = schema->find(object_type); + auto &schema = realm->schema(); + auto object_schema = schema.find(object_type); - if (object_schema == schema->end()) { + if (object_schema == schema.end()) { throw std::runtime_error("Object type '" + object_type + "' not found in schema."); } return *object_schema; @@ -268,7 +268,7 @@ static inline void convert_outdated_datetime_columns(const SharedRealm &realm) { realm::util::Optional old_file_format_version = realm->file_format_upgraded_from_version(); if (old_file_format_version && old_file_format_version < 5) { // any versions earlier than file format 5 are stored as milliseconds and need to be converted to the new format - for (auto& object_schema : *realm->config().schema) { + for (auto& object_schema : realm->schema()) { auto table = ObjectStore::table_for_object_type(realm->read_group(), object_schema.name); for (auto& property : object_schema.persisted_properties) { if (property.type == realm::PropertyType::Date) { @@ -321,13 +321,15 @@ void RealmClass::constructor(ContextType ctx, ObjectType this_object, size_t static const String read_only_string = "readOnly"; ValueType read_only_value = Object::get_property(ctx, object, read_only_string); - config.read_only = Value::is_undefined(ctx, read_only_value) ? false : Value::validated_to_boolean(ctx, read_only_value, "readOnly"); + if (!Value::is_undefined(ctx, read_only_value) && Value::validated_to_boolean(ctx, read_only_value, "readOnly")) { + config.schema_mode = SchemaMode::ReadOnly; + } static const String schema_string = "schema"; ValueType schema_value = Object::get_property(ctx, object, schema_string); if (!Value::is_undefined(ctx, schema_value)) { ObjectType schema_object = Value::validated_to_object(ctx, schema_value, "schema"); - config.schema.reset(new realm::Schema(Schema::parse_schema(ctx, schema_object, defaults, constructors))); + config.schema.emplace(Schema::parse_schema(ctx, schema_object, defaults, constructors)); schema_updated = true; } @@ -344,7 +346,7 @@ void RealmClass::constructor(ContextType ctx, ObjectType this_object, size_t ValueType migration_value = Object::get_property(ctx, object, migration_string); if (!Value::is_undefined(ctx, migration_value)) { FunctionType migration_function = Value::validated_to_function(ctx, migration_value, "migration"); - config.migration_function = [=](SharedRealm old_realm, SharedRealm realm) { + config.migration_function = [=](SharedRealm old_realm, SharedRealm realm, realm::Schema&) { auto old_realm_ptr = new SharedRealm(old_realm); auto realm_ptr = new SharedRealm(realm); ValueType arguments[2] = { @@ -459,19 +461,19 @@ void RealmClass::get_path(ContextType ctx, ObjectType object, ReturnValue &re template void RealmClass::get_schema_version(ContextType ctx, ObjectType object, ReturnValue &return_value) { - double version = get_internal>(object)->get()->config().schema_version; + double version = get_internal>(object)->get()->schema_version(); return_value.set(version); } template void RealmClass::get_schema(ContextType ctx, ObjectType object, ReturnValue &return_value) { - auto schema = get_internal>(object)->get()->config().schema.get(); - return_value.set(Schema::object_for_schema(ctx, *schema)); + auto& schema = get_internal>(object)->get()->schema(); + return_value.set(Schema::object_for_schema(ctx, schema)); } template void RealmClass::get_read_only(ContextType ctx, ObjectType object, ReturnValue &return_value) { - return_value.set(get_internal>(object)->get()->config().read_only); + return_value.set(get_internal>(object)->get()->config().read_only()); } template @@ -574,7 +576,7 @@ void RealmClass::delete_all(ContextType ctx, ObjectType this_object, size_t a throw std::runtime_error("Can only delete objects within a transaction."); } - for (auto objectSchema : *realm->config().schema) { + for (auto objectSchema : realm->schema()) { ObjectStore::table_for_object_type(realm->read_group(), objectSchema.name)->clear(); } } diff --git a/src/js_results.hpp b/src/js_results.hpp index 3913bb83..6f1ef8e9 100644 --- a/src/js_results.hpp +++ b/src/js_results.hpp @@ -94,7 +94,7 @@ typename T::Object ResultsClass::create_filtered(ContextType ctx, const U &co parser::Predicate predicate = parser::parse(query_string); query_builder::ArgumentConverter converter(ctx, realm, args); - query_builder::apply_predicate(query, predicate, converter, *realm->config().schema, object_schema.name); + query_builder::apply_predicate(query, predicate, converter, realm->schema(), object_schema.name); return create_instance(ctx, realm::Results(realm, std::move(query))); }