Skip to content

v0.2.0-preview

Pre-release
Pre-release
Compare
Choose a tag to compare
@leemaguire leemaguire released this 22 Jun 16:55
· 69 commits to main since this release
f5da2dc

Enhancements

This preview introduces a new way to declare your object model, bringing you closer to feeling like you're interfacing with POCO's.

namespace realm::experimental {
    struct Address {
        std::string street;
        std::string city;
        std::string country;
    };
    REALM_EMBEDDED_SCHEMA(Address, street, city, country)

    struct Person {
        primary_key<int64_t> _id;
        std::string name;
        int64_t age;
        Address* address = nullptr;
    };
    REALM_SCHEMA(Person, _id, name, age, address)
}

This also allows for automatic schema discovery, so opening a realm is now achieved with realm::experimental::db(std::move(some_realm_config).
These new features are available under the realm::experimental namespace.
New API usage is as follows:

  #include <cpprealm/experimental/sdk.hpp>
  using namespace realm::experimental;
  ...
  auto realm = db(std::move(config));
  
  auto address = Address();
  address.city = "New York";
  auto person = Person();
  person.name = "John";
  person.address = &address;
  
  auto managed_person = realm.write([&person, &realm] {
      return realm.add(std::move(person));
  });
  
  // Note that `person` has been consumed as an rvalue and `managed_person` 
  // should now be used for any data access or observation.

Other API enhancements:

  • Object links are now declared with pointer syntax.
  • Added support for linking objects:
      struct Dog;
      struct Person {
          primary_key<int64_t> _id;
          ...
          Dog* dog;
      };
      REALM_SCHEMA(Person, _id, name, age, dog)
      struct Dog {
          ...
          linking_objects<&Person::dog> owners;
      };
    
      // Sample Usage:
      my_realm.objects<experimental::Dog>()[0].owners.size();
    
  • Primary keys of int64_t, std::string and realm::uuid and their optional counterparts are now supported.

Usage of Realm under this namespace is also compatible with Windows (MSVC 19.30 and greater).

Breaking Changes

The following functions now return std::future instead of std::promise

  • realm::App::login
  • realm::App::register_user
  • realm::user::logout,
  • realm::sync_subscription_set::update
  • realm::sync_session::wait_for_upload_completion
  • realm::sync_session::wait_for_download_completion

Compatibility

  • Fileformat: Generates files with format v22.

Internals

  • Upgraded to Core v13.15.1