Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add string-based access API for RealmObject #524

Closed
wants to merge 7 commits into from

Conversation

nirinchev
Copy link
Member

@nirinchev nirinchev commented Apr 29, 2022

Adds a string-based API to read properties of a RealmObject. Right now we only support reading as that's required to get migrations working, but it can be extended in the future to also support setting.

The API is the following:

final obj = realm.dynamic.find("Foo", 123);

// Get simple primitive
final str = obj.dynamic.get<String>("stringProp");

// Get another object
final bar = obj.dynamic.get<RealmObject>("bar");
final barString = bar.dynamic.get<String>("stringProp");

// Get a list of objects
final bars = obj.dynamic.getList<RealmObject>("bars");

// Iterate the list as normal
for (final bar in bars) {
  print(bar.dynamic.get<DateTime>("dateProp");
}

Part of #70.

@cla-bot cla-bot bot added the cla: yes label Apr 29, 2022
@nirinchev nirinchev self-assigned this Apr 29, 2022
@nirinchev nirinchev changed the title [WIP] Add string-based access API for RealmObject Add string-based access API for RealmObject May 2, 2022
@nirinchev nirinchev marked this pull request as ready for review May 2, 2022 11:43
lib/src/realm_object.dart Outdated Show resolved Hide resolved
@@ -267,6 +269,8 @@ mixin RealmObject on RealmEntity {
final controller = RealmObjectNotificationsController<T>(object);
return controller.createStream();
}

late final DynamicRealmObject dynamic = DynamicRealmObject._(this);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a super huge fan of hiding this API under a dynamic property like we did in .NET :/

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The API is kind of large and niche, so I'd rather not pollute the main interface but happy to discuss alternatives.

@blagoev blagoev marked this pull request as draft May 20, 2022 05:43
@nirinchev
Copy link
Member Author

Superseded by #853.

@nirinchev nirinchev closed this Aug 18, 2022
@nirinchev nirinchev deleted the ni/dynamic-realm-object branch August 22, 2022 16:44
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants